You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by phrocker <gi...@git.apache.org> on 2018/03/20 14:00:56 UTC

[GitHub] nifi-minifi-cpp pull request #286: MINIFICPP-438: Preform string to correct ...

GitHub user phrocker opened a pull request:

    https://github.com/apache/nifi-minifi-cpp/pull/286

    MINIFICPP-438: Preform string to correct test failure for verifying t…

    …hat json embedded strings will be unescaped
    
    Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
         in the commit message?
    
    - [ ] Does your PR title start with MINIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [ ] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
    - [ ] If applicable, have you updated the LICENSE file?
    - [ ] If applicable, have you updated the NOTICE file?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/phrocker/nifi-minifi-cpp MINIFICPP-438

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi-minifi-cpp/pull/286.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #286
    
----
commit bccb48134b842d594fb7f53f46f56385634e7b96
Author: Marc Parisi <ph...@...>
Date:   2018-03-20T13:52:14Z

    MINIFICPP-438: Preform string to correct test failure for verifying that json embedded strings will be unescaped

----


---

[GitHub] nifi-minifi-cpp issue #286: MINIFICPP-438: Preform string to correct test fa...

Posted by achristianson <gi...@git.apache.org>.
Github user achristianson commented on the issue:

    https://github.com/apache/nifi-minifi-cpp/pull/286
  
    Fixed the decode method in #290 


---

[GitHub] nifi-minifi-cpp pull request #286: MINIFICPP-438: Preform string to correct ...

Posted by phrocker <gi...@git.apache.org>.
Github user phrocker closed the pull request at:

    https://github.com/apache/nifi-minifi-cpp/pull/286


---

[GitHub] nifi-minifi-cpp issue #286: MINIFICPP-438: Preform string to correct test fa...

Posted by phrocker <gi...@git.apache.org>.
Github user phrocker commented on the issue:

    https://github.com/apache/nifi-minifi-cpp/pull/286
  
    @achristianson i agreed that something else should likely be done. Feel free to take that on. My goal was to solve the test failure. 


---

[GitHub] nifi-minifi-cpp issue #286: MINIFICPP-438: Preform string to correct test fa...

Posted by achristianson <gi...@git.apache.org>.
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.


---

[GitHub] nifi-minifi-cpp issue #286: MINIFICPP-438: Preform string to correct test fa...

Posted by achristianson <gi...@git.apache.org>.
Github user achristianson commented on the issue:

    https://github.com/apache/nifi-minifi-cpp/pull/286
  
    ...also I think it would need to be
    
    ```json
    ["string val"]
    ```
    or
    ```json
    {"dummy_key": "string_val"}
    ```
    to really be universally valid, not just
    
    ```json
    {"string val"}
    ```
    ...because there is no key/val pair in that object.


---

[GitHub] nifi-minifi-cpp issue #286: MINIFICPP-438: Preform string to correct test fa...

Posted by phrocker <gi...@git.apache.org>.
Github user phrocker commented on the issue:

    https://github.com/apache/nifi-minifi-cpp/pull/286
  
    My intent was to not form a valid JSON document but to instead continue the spirit of the test. 


---