Permalink
Browse files

fix bug 770947: Allow escaped single or double quotes in any quoting …

…context
  • Loading branch information...
1 parent 826ad90 commit ef64c66effa02766740f847d180c07cbfebc7084 @lmorchard committed Jul 6, 2012
Showing with 37 additions and 9 deletions.
  1. +13 −9 lib/kumascript/parser.pegjs
  2. +13 −0 tests/fixtures/macros-document-escaped-quotes.txt
  3. +11 −0 tests/test-macros.js
@@ -68,21 +68,25 @@ ArgumentList
}
Argument
- = c:( Number / DoubleArgumentChars / SingleArgumentChars )
+ = c:( Number / DoubleQuotedArgumentChars / SingleQuotedArgumentChars )
Number = c:[\-.0-9]+ { return parseInt(c.join('')); }
-DoubleArgumentChars
- = '"' c:DoubleArgumentChar+ '"' { return c.join(''); }
+DoubleQuotedArgumentChars
+ = '"' c:DoubleQuotedArgumentChar+ '"' { return c.join(''); }
-SingleArgumentChars
- = "'" c:SingleArgumentChar+ "'" { return c.join(''); }
+SingleQuotedArgumentChars
+ = "'" c:SingleQuotedArgumentChar+ "'" { return c.join(''); }
-DoubleArgumentChar
- = [^"\\] / '\\"' { return '"'; }
+DoubleQuotedArgumentChar
+ = [^"\\] /
+ "\\'" { return "'"; } /
+ '\\"' { return '"'; }
-SingleArgumentChar
- = [^'\\] / "\\'" { return "'"; }
+SingleQuotedArgumentChar
+ = [^'\\] /
+ "\\'" { return "'"; } /
+ '\\"' { return '"'; }
__ = whitespace*
@@ -0,0 +1,13 @@
+* {{ fake('This is a "test"') }}
+* {{ fake("This is a 'test'") }}
+* {{ fake("This is a \"test\"") }}
+* {{ fake('This is a \'test\'') }}
+* {{ fake("This is a \'test\'") }}
+* {{ fake('This is a \"test\"') }}
+---
+* ["fake",["This is a \"test\""]]
+* ["fake",["This is a 'test'"]]
+* ["fake",["This is a \"test\""]]
+* ["fake",["This is a 'test'"]]
+* ["fake",["This is a 'test'"]]
+* ["fake",["This is a \"test\""]]
View
@@ -87,6 +87,17 @@ module.exports = nodeunit.testCase({
});
},
+ "Escaped single and double quotes should work in any quoting context": function (test) {
+ var mp = new ks_macros.MacroProcessor({
+ loader_class: ks_test_utils.JSONifyLoader
+ });
+ processFixture(test, mp, 'macros-document-escaped-quotes.txt',
+ function (errors, result) {
+ test.ok(!errors, "There should be no errors");
+ test.done();
+ });
+ },
+
"Double right brace in a document should not result in a syntax error": function (test) {
var mp = new ks_macros.MacroProcessor({
loader_class: ks_test_utils.JSONifyLoader

0 comments on commit ef64c66

Please sign in to comment.