Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git://github.com/mozilla/kumascript

  • Loading branch information...
commit d8cb04351bdb0b058db6b78d04f378b60d376bf9 2 parents 5704b81 + 19625f1
Les Orchard authored
Showing with 26 additions and 1 deletion.
  1. +4 −1 lib/kumascript/parser.pegjs
  2. +22 −0 tests/test-parser.js
5 lib/kumascript/parser.pegjs
View
@@ -83,7 +83,10 @@ JSONString
JSONChar
= [^"\\] /
- "\\" ( ["bfnrt\\/] / "u" [0-9] [0-9] [0-9] [0-9] )
+ "\\" ( ["bfnrt\\/] / "u" HexDigit HexDigit HexDigit HexDigit )
+
+HexDigit
+ = [0-9A-Fa-f]
JSONNumber
= "-" ? ( "0" / [1-9] [0-9]* ) ( "." [0-9]+ )? ( [eE] [+-]? [0-9]+ )?
22 tests/test-parser.js
View
@@ -53,5 +53,27 @@ module.exports = nodeunit.testCase({
test.deepEqual(tokens, [{type: "MACRO", name: "f", args: [{a: []}], offset: 0}],
"Empty JSON objects are parsed correctly");
test.done();
+ },
+
+ "Escaped Unicode codepoints are parsed correctly": function (test) {
+ var tokens = ks_parser.parse('{{ f({ "a": "\\u00f3" }) }}');
+ test.deepEqual(tokens,
+ [{type: "MACRO", name: "f", args: [{a: "\u00f3"}], offset: 0}],
+ "Lowercase hex digits are parsed correctly");
+
+ var tokens = ks_parser.parse('{{ f({ "a": "\\u00F3" }) }}');
+ test.deepEqual(tokens,
+ [{type: "MACRO", name: "f", args: [{a: "\u00f3"}], offset: 0}],
+ "Uppercase hex digits are parsed correctly");
+
+ test.throws(function() {
+ ks_parser.parse('{{ f({ "a": "\\uGHIJ" }) }}');
+ }, PEG.parser.SyntaxError, "Non-hexadecimal characters are not allowed");
+
+ test.throws(function() {
+ ks_parser.parse('{{ f({ "a": "\\uFF" }) }}');
+ }, PEG.parser.SyntaxError, "Four digits are required");
+
+ test.done();
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.