-
Notifications
You must be signed in to change notification settings - Fork 468
Handle non-printable control characters when escaping JSON #7435
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
Handle non-printable control characters when escaping JSON #7435
Conversation
@@ -1,153 +1,14 @@ | |||
let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) | |||
type t = Ext_json_noloc.t |
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.
The existing Ext_json
tests were moved to tests/ounit_tests/ounit_ext_json_tests.ml
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/win32-x64
commit: |
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.
This is looking good to me, thank you! @cristianoc any thoughts?
Looks great! |
When the VS Code extension calls
rescript-editor-analysis
, it replies with JSON serialised by analysis/vendor/json/Json.ml.While
Json.escape
escapes printable characters correctly, it did not handle non-printable control characters (i.e. characters with a char code < 0x20). This meant that JSON sent to VS code was not always escaped properly and prevented code actions from being available in certain situations.For example, opening up https://github.com/rescript-lang/rescript-lang.org/blob/master/src/bindings/RescriptCompilerApi.res in VS Code currently results in
SyntaxError: Bad control character in string literal in JSON at position 1319 (line 15 column 751)
:In the example above, this is caused by
Warning.toCompactErrorLine
containing a string with control character0x27
.With the escaping logic I've added, this issue no longer occurs.
Changes I've made
analysis/vendor/json/Json.ml
tests/ounit_tests/ounit_json_tests.ml
totests/ounit_tests/ounit_ext_json_tests.ml
tests/ounit_tests/ounit_json_tests.ml
test suite foranalysis/vendor/json/Json.ml
compiler/ext/ext_json_noloc.ml
, which is used by the bsb watcherFuture work
analysis/vendor/json/Json.ml
andcompiler/ext/ext_json
should probably be eventually replaced with Yojson