Skip to content

Commit

Permalink
Fix issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
padolsey committed Jun 9, 2013
1 parent ee71157 commit bf67f2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@
function resolveStringToken(tok) {
return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)]
}

// Replace HTML with string tokens first
input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) {
return '%%__HTML_TOKEN___%%' + (stringTokens.push(
$2.replace(/\\`/g, '\`')
) - 1);
});

input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) {
return '%%__STRING_TOKEN___%%' + (stringTokens.push(
$2.replace(/\\'/g, '\'').replace(/\\"/g, '"')
) - 1);
});

input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) {
return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push($2) - 1);
});

// Replace HTML with string tokens too
input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) {
return '%%__HTML_TOKEN___%%' + (stringTokens.push(
$2.replace(/\\`/g, '\`')
) - 1);
});

var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input);

// Remove comments:
Expand Down
3 changes: 3 additions & 0 deletions test/DefaultGeneratorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ describe('DefaultParser: HTML Generation', function() {
it('Does not escape backticked text', function() {
expect('`O < K`').toGenerate('O < K');
});
it('Quotes strings are not parsed within backticks', function() {
expect('` "this" and \'this ... \' ..`').toGenerate(' "this" and \'this ... \' ..');
});
it('Does not escape backticked attribute values', function() {
expect('d { id: `<<` }').toGenerate('<d id="<<"></d>');
});
Expand Down

0 comments on commit bf67f2e

Please sign in to comment.