-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Invalid JSON (quotes not escaped) #2955 #3012
FIX Invalid JSON (quotes not escaped) #2955 #3012
Conversation
src/lib/rest/rest.cpp
Outdated
@@ -111,7 +111,7 @@ static int uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* ckey, c | |||
|
|||
if (val == NULL || *val == 0) | |||
{ | |||
std::string errorString = std::string("Empty right-hand-side for URI param /") + ckey + "/"; | |||
std::string errorString = std::string("Empty right-hand-side for URI param /") + jsonInvalidCharsTransformation(ckey) + "/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mention in #2955 (comment), I think is better to fix this at OrionError::toJson(). I guess it should be easy to move the fix.
src/lib/rest/rest.cpp
Outdated
@@ -111,7 +111,7 @@ static int uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* ckey, c | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a line to the CHANGE_NEXT_RELEASE file about this fix. Proposal:
- Fix: broken JSON due to unscaped quotes (") in NGSIv2 error description field (#2955)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! Please have a look to the line comment among the code and also the comments in the issue this PR is solving (#2955)
In addition, could you edit the PR body to include a reference to the issue which this PR is fixing (#2955), please? That helps a lot to cross-referencing.
Invalid chars transformation is now performed in the OrionError::toJson() method, by using the **htmlEscape** function. The test was modified accordingly.
- CHANGE_NEXT_RELEASE updated
src/lib/rest/OrionError.cpp
Outdated
free(detailsEscaped); | ||
|
||
return out; | ||
// return "{" + JSON_STR("error") + ":" + JSON_STR(reasonPhrase) + "," + JSON_STR("description") + ":" + JSON_STR(details) + "}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover comment and 3 blank lines should be removed, pls.
Code cleaned
It looks good! Howerver, note you have conflict with master branch that avoid merging this PR. I guess that is a small line disalingment in the CHANGES_NEXT_RELEASE file. The solution is to upgrade your branch with master and solve the conflict. |
into 2955_quote_in_url_not_escaped # Conflicts: # CHANGES_NEXT_RELEASE
LGTM. Thx! For the next PR, please end each line comment thread with a
|
LGTM |
@arigliano for next PRs please pay attention to execute a full regression of functional tests (i.e. I'm saying this because after the changes merged in this PR, the following test were failing:
Not a big problem, as they have been quickly fixed in PR #3016, but please take this into account in the future. Thank you very much for your collaboration! |
For a full regression, better to use Another way to run the functional tests is to use the The script
I often use |
In this case, please ensure you have the contextBroker binary correctly installed in your execution path. If you forget that, you can get crazy after doing some changes in your code that compile (i.e. |
This PR fixes #2955
As described in issue comments, this fix consists of:
Let me know if this is ok or alternative approaches are preferable.
In addition, it was implemented a new functional test, which passes, as well as existing ones.