Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "\\{{" immediately following "\{{" #646

Merged
merged 1 commit into from
Dec 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions spec/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ describe('Tokenizer', function() {

it('supports escaping multiple escape characters', function() {
var result = tokenize("{{foo}} \\\\{{bar}} \\\\{{baz}}");
result.should.match_tokens(['OPEN', 'ID', 'CLOSE', 'CONTENT', 'OPEN', 'ID', 'CLOSE', 'CONTENT', 'OPEN', 'ID', 'CLOSE']);
result.should.match_tokens(['OPEN', 'ID', 'CLOSE', 'CONTENT', 'OPEN', 'ID', 'CLOSE', 'CONTENT', 'OPEN', 'ID', 'CLOSE']);

result[3].should.be_token("CONTENT", " \\");
result[5].should.be_token("ID", "bar");
result[7].should.be_token("CONTENT", " \\");
result[9].should.be_token("ID", "baz");
result[3].should.be_token("CONTENT", " \\");
result[5].should.be_token("ID", "bar");
result[7].should.be_token("CONTENT", " \\");
result[9].should.be_token("ID", "baz");
});

it('supports mixed escaped delimiters and escaped escape characters', function() {
it('supports escaped mustaches after escaped escape characters', function() {
var result = tokenize("{{foo}} \\\\{{bar}} \\{{baz}}");
result.should.match_tokens(['OPEN', 'ID', 'CLOSE', 'CONTENT', 'OPEN', 'ID', 'CLOSE', 'CONTENT', 'CONTENT', 'CONTENT']);

Expand All @@ -107,6 +107,16 @@ describe('Tokenizer', function() {
result[8].should.be_token("CONTENT", "{{baz}}");
});

it('supports escaped escape characters after escaped mustaches', function() {
var result = tokenize("{{foo}} \\{{bar}} \\\\{{baz}}");
result.should.match_tokens(['OPEN', 'ID', 'CLOSE', 'CONTENT', 'CONTENT', 'CONTENT', 'OPEN', 'ID', 'CLOSE']);

result[4].should.be_token("CONTENT", "{{bar}} ");
result[5].should.be_token("CONTENT", "\\");
result[6].should.be_token("OPEN", "{{");
result[7].should.be_token("ID", "baz");
});

it('supports escaped escape character on a triple stash', function() {
var result = tokenize("{{foo}} \\\\{{{bar}}} {{baz}}");
result.should.match_tokens(['OPEN', 'ID', 'CLOSE', 'CONTENT', 'OPEN_UNESCAPED', 'ID', 'CLOSE_UNESCAPED', 'CONTENT', 'OPEN', 'ID', 'CLOSE']);
Expand Down
6 changes: 3 additions & 3 deletions src/handlebars.l
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD}

[^\x00]+ return 'CONTENT';

<emu>[^\x00]{2,}?/("{{"|<<EOF>>) {
if(yytext.slice(-1) !== "\\") this.popState();
if(yytext.slice(-1) === "\\") strip(0,1);
// marks CONTENT up to the next mustache or escaped mustache
<emu>[^\x00]{2,}?/("{{"|"\\{{"|"\\\\{{"|<<EOF>>) {
this.popState();
return 'CONTENT';
}

Expand Down