Skip to content

Commit

Permalink
Merge pull request mdn#23 from lmorchard/no-trimmed-decimals-782930
Browse files Browse the repository at this point in the history
fix bug 782930: Don't use parseInt() to parse numeric arguments
  • Loading branch information
groovecoder committed Aug 16, 2012
2 parents 7d07d36 + 893d998 commit 0431a1a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/kumascript/parser.pegjs
Expand Up @@ -103,7 +103,7 @@ ArgumentList
Argument
= c:( Number / DoubleQuotedArgumentChars / SingleQuotedArgumentChars )

Number = c:[\-.0-9]+ { return parseInt(c.join('')); }
Number = c:[\-.0-9]+ { return c.join(''); }

DoubleQuotedArgumentChars
= '"' c:DoubleQuotedArgumentChar* '"' { return c.join(''); }
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/documents/document1-expected.txt
Expand Up @@ -9,4 +9,4 @@ Here is { some text } with braces, but not a macro.

Look, it's JSON without escaping: ["a","b","c"]

Here is a multi-line macro: ["With many","parameters","including \"quoted\"","text of both 'kinds'","even \"escaped\"","like 'these'","and numbers",-10,0,0,10,100] that even works inline.
Here is a multi-line macro: ["With many","parameters","including \"quoted\"","text of both 'kinds'","even \"escaped\"","like 'these'","and numbers","-10","0","0.1","10","100"] that even works inline.
3 changes: 3 additions & 0 deletions tests/fixtures/macros-decimal-argument.txt
@@ -0,0 +1,3 @@
* {{fx_minversion_header(3.6)}}
---
* ["fx_minversion_header",["3.6"]]
2 changes: 1 addition & 1 deletion tests/fixtures/macros1.txt
Expand Up @@ -36,6 +36,6 @@ The following items are all macros, though:
* ["ParenTastic",["()()()"]]
* ["Bracepocalypse",["{{}}{{}}{{}}"]]

Here is a ["MultiLineMacro",["With many","parameters","including \"quoted\"","text of both 'kinds'","even \"escaped\"","like 'these'","and numbers",-10,0,0,10,100]] that even works inline.
Here is a ["MultiLineMacro",["With many","parameters","including \"quoted\"","text of both 'kinds'","even \"escaped\"","like 'these'","and numbers","-10","0","0.1","10","100"]] that even works inline.

Here is a ["MacroWithJson",[{"es":"es/JavaScript/Acerca_de_JavaScript","en":"en/JavaScript/About_JavaScript"}]] that even works inline.
12 changes: 12 additions & 0 deletions tests/test-macros.js
Expand Up @@ -89,6 +89,18 @@ module.exports = nodeunit.testCase({
});
},

"A numeric macro argument with a decimal point should not be trimmed to an integer": function (test) {
var mp = new ks_macros.MacroProcessor({
macro_timeout: 500,
loader_class: ks_test_utils.JSONifyLoader
});
processFixture(test, mp, 'macros-decimal-argument.txt',
function (errors, result) {
test.ok(!errors, "There should be no errors");
test.done();
});
},

"Escaped single and double quotes should work in any quoting context": function (test) {
var mp = new ks_macros.MacroProcessor({
macro_timeout: 500,
Expand Down

0 comments on commit 0431a1a

Please sign in to comment.