Skip to content

Commit

Permalink
bsjs: fix handling of escape seq in strings
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jan 29, 2013
1 parent ccebf52 commit fb7d51c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/ometajs/grammars/bsjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,11 @@ BSJSParser._isReserved = function(k) {
};

function preparseString(str) {
return str.replace(/\\x([0-9a-f]{2})/ig, "\\u00$1");
return str.replace(/\\x([0-9a-f]{2})/ig, "\\u00$1").replace(/\\([0-9]{3})/ig, function(all, num) {
var str = parseInt(num, 8).toString("hex");
while (str.length < 4) str = "0" + str;
return "\\u" + str;
}).replace(/\\([^bfnOrtv'\\])|(\\.)/ig, "$1");
}

var BSSemActionParser = function BSSemActionParser(source, opts) {
Expand Down
8 changes: 7 additions & 1 deletion lib/ometajs/grammars/bsjs.ometajs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ return BSJSParser.reserved.hasOwnProperty(k);
};

function preparseString(str) {
return str.replace(/\\x([0-9a-f]{2})/ig, '\\u00$1');
return str.replace(/\\x([0-9a-f]{2})/ig, '\\u00$1')
.replace(/\\([0-9]{3})/ig, function(all, num) {
var str = parseInt(num, 8).toString('hex');
while (str.length < 4) str = '0' + str;
return '\\u' + str;
})
.replace(/\\([^bfnOrtv'\\])|(\\.)/ig, '$1');
}


Expand Down
5 changes: 5 additions & 0 deletions test/unit/functional-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ suite('Ometajs module', function() {
'begin',
['stmt',['parens', ['get', 'a']]]
]);

js('"a\\-b\\-c"', [
'begin',
['stmt',['string', 'a-b-c']]
]);
});

suite('should parse real javascript like', function() {
Expand Down

0 comments on commit fb7d51c

Please sign in to comment.