diff options
author | Nikola Knezevic <nikola@dfinity.org> | 2020-01-07 00:06:49 +0100 |
---|---|---|
committer | Nikola Knezevic <nikola@dfinity.org> | 2020-01-07 00:09:58 +0100 |
commit | 52a8f9295b828872586c5b9e5587064a25dae9b2 (patch) | |
tree | 90f425de9ad98a572043e64b382009872f930be2 /tests | |
parent | cb2d348d48cfd66fa34edd5df8c255cf74170a84 (diff) |
Add support for \u escape in fromJSON
As fromTOML supports \u and \U escapes, bring fromJSON on par. As JSON defaults
to UTF-8 encoding (every JSON parser must support UTF-8), this change parses the
`\u hex hex hex hex` sequence (\u followed by 4 hexadecimal digits) into an
UTF-8 representation.
Add a test to verify correct parsing, using all escape sequences from json.org.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lang/eval-okay-fromjson-escapes.exp | 1 | ||||
-rw-r--r-- | tests/lang/eval-okay-fromjson-escapes.nix | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/tests/lang/eval-okay-fromjson-escapes.exp b/tests/lang/eval-okay-fromjson-escapes.exp new file mode 100644 index 000000000..add5505a8 --- /dev/null +++ b/tests/lang/eval-okay-fromjson-escapes.exp @@ -0,0 +1 @@ +"quote \" reverse solidus \\ solidus / backspace formfeed newline \n carriage return \r horizontal tab \t 1 char unicode encoded backspace 1 char unicode encoded e with accent é 2 char unicode encoded s with caron š 3 char unicode encoded rightwards arrow →" diff --git a/tests/lang/eval-okay-fromjson-escapes.nix b/tests/lang/eval-okay-fromjson-escapes.nix new file mode 100644 index 000000000..f00713507 --- /dev/null +++ b/tests/lang/eval-okay-fromjson-escapes.nix @@ -0,0 +1,3 @@ +# This string contains all supported escapes in a JSON string, per json.org +# \b and \f are not supported by Nix +builtins.fromJSON ''"quote \" reverse solidus \\ solidus \/ backspace \b formfeed \f newline \n carriage return \r horizontal tab \t 1 char unicode encoded backspace \u0008 1 char unicode encoded e with accent \u00e9 2 char unicode encoded s with caron \u0161 3 char unicode encoded rightwards arrow \u2192"'' |