[ 
https://issues.apache.org/jira/browse/MINIFICPP-438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16406701#comment-16406701
 ] 

ASF GitHub Bot commented on MINIFICPP-438:
------------------------------------------

Github user achristianson commented on the issue:

    https://github.com/apache/nifi-minifi-cpp/pull/286
  
    I looked into this and it's really a problem with the escape/unescape JSON. 
We're not aiming to parse/unparse a JSON object, but rather to prepare a string 
for use in JSON. The escape/unescape EL functions use RapidJSON functions to 
handle the escaping/unescaping by putting the target value into a string JSON 
object and stripping the quotes.
    
    Your change is correct in spirit that wrapping the string in an object 
container makes it compatible with RFC4627 and RFC7159.
    
    The change needs to happen in one of these, from Expression.cpp:
    
    ```c++
    Value expr_escapeJson(const std::vector<Value> &args) {
      const std::string &arg_0 = args[0].asString();
      rapidjson::StringBuffer buf;
      rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
      writer.String(arg_0.c_str());
      std::string result(buf.GetString());
      return Value(result.substr(1, result.length()-2));
    }
    
    Value expr_unescapeJson(const std::vector<Value> &args) {
      std::stringstream arg_0_ss;
      arg_0_ss << "\"" << args[0].asString() << "\"";
      rapidjson::Reader reader;
      rapidjson::StringStream ss(arg_0_ss.str().c_str());
      rapidjson::Document doc;
      doc.ParseStream(ss);
      if (doc.IsString()) {
        return Value(std::string(doc.GetString()));
      } else {
        return Value();
      }
    }
    ```
    
    Either the object wrap/unwrap code should be moved here (instead of the 
test case), or a different technique altogether should be used for JSON 
escape/unescape.
    
    Feel free to update this PR/add a new PR or I can handle it if you want.


> Expression language test fails with json unescape procedure
> -----------------------------------------------------------
>
>                 Key: MINIFICPP-438
>                 URL: https://issues.apache.org/jira/browse/MINIFICPP-438
>             Project: NiFi MiNiFi C++
>          Issue Type: Improvement
>            Reporter: marco polo
>            Assignee: marco polo
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to