diff options
author | Daniel Marcotte <dmarcotte@gmail.com> | 2013-08-24 12:18:12 -0700 |
---|---|---|
committer | Daniel Marcotte <dmarcotte@gmail.com> | 2013-10-13 09:03:02 -0400 |
commit | 468fa8b6dd743431ac42cc2b6ad351ea4506561d (patch) | |
tree | d9fb065092ff50b5ba29e9542f29bb0930926c35 /spec/tokenizer.js | |
parent | e9350f29327289b3c9a5950d6392254d43767065 (diff) | |
download | handlebars.js-468fa8b6dd743431ac42cc2b6ad351ea4506561d.zip handlebars.js-468fa8b6dd743431ac42cc2b6ad351ea4506561d.tar.gz handlebars.js-468fa8b6dd743431ac42cc2b6ad351ea4506561d.tar.bz2 |
Fix "\\" escaping
Previously, "\\{{foo}}" would only result in the desired "\fooValue" if
it was at the beginning of the file or immediately after a close stache.
Diffstat (limited to 'spec/tokenizer.js')
-rw-r--r-- | spec/tokenizer.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/tokenizer.js b/spec/tokenizer.js index f86774a..de981e4 100644 --- a/spec/tokenizer.js +++ b/spec/tokenizer.js @@ -58,6 +58,7 @@ describe('Tokenizer', function() { var result = tokenize("{{foo}} \\{{bar}} {{baz}}"); result.should.match_tokens(['OPEN', 'ID', 'CLOSE', 'CONTENT', 'CONTENT', 'OPEN', 'ID', 'CLOSE']); + result[3].should.be_token("CONTENT", " "); result[4].should.be_token("CONTENT", "{{bar}} "); }); @@ -77,6 +78,43 @@ describe('Tokenizer', function() { result[4].should.be_token("CONTENT", "{{{bar}}} "); }); + it('supports escaping escape character', function() { + var result = tokenize("{{foo}} \\\\{{bar}} {{baz}}"); + 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"); + }); + + 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[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() { + var result = tokenize("{{foo}} \\\\{{bar}} \\{{baz}}"); + result.should.match_tokens(['OPEN', 'ID', 'CLOSE', 'CONTENT', 'OPEN', 'ID', 'CLOSE', 'CONTENT', 'CONTENT', 'CONTENT']); + + result[3].should.be_token("CONTENT", " \\"); + result[4].should.be_token("OPEN", "{{"); + result[5].should.be_token("ID", "bar"); + result[7].should.be_token("CONTENT", " "); + result[8].should.be_token("CONTENT", "{{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']); + + result[3].should.be_token("CONTENT", " \\"); + result[5].should.be_token("ID", "bar"); + }); + it('tokenizes a simple path', function() { var result = tokenize("{{foo/bar}}"); result.should.match_tokens(['OPEN', 'ID', 'SEP', 'ID', 'CLOSE']); |