Skip to content

Commit c1020a0

Browse files
committed
Add unicode support for ID tokens
Fixes handlebars-lang#433 Fixes handlebars-lang#469
1 parent bff71d7 commit c1020a0

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

dist/handlebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ case 33: return 5;
644644
break;
645645
}
646646
};
647-
lexer.rules = [/^(?:\\\\(?=(\{\{)))/,/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[}/ ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:-?[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$:\-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:\s+)/,/^(?:[a-zA-Z0-9_$\-\/\.]+)/,/^(?:$)/];
647+
lexer.rules = [/^(?:\\\\(?=(\{\{)))/,/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[}\/ ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:-?[0-9]+(?=[}\s]))/,/^(?:[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:\s+)/,/^(?:[a-zA-Z0-9_$\-\/\.]+)/,/^(?:$)/];
648648
lexer.conditions = {"mu":{"rules":[5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,33],"inclusive":false},"emu":{"rules":[3],"inclusive":false},"com":{"rules":[4],"inclusive":false},"par":{"rules":[31,32],"inclusive":false},"INITIAL":{"rules":[0,1,2,33],"inclusive":true}};
649649
return lexer;})()
650650
parser.lexer = lexer;

release-notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- [#515](https://github.com/wycats/handlebars.js/issues/515) - Add node require extensions support ([@jjclark1982](https://github.com/jjclark1982))
55
- [#517](https://github.com/wycats/handlebars.js/issues/517) - Fix amd precompiler output with directories ([@blessenm](https://github.com/blessenm))
66
- [#519](https://github.com/wycats/handlebars.js/issues/519) - Fix partials with . name ([@jamesgorrie](https://github.com/jamesgorrie))
7+
- [#433](https://github.com/wycats/handlebars.js/issues/433) - Add support for unicode ids
8+
- [#469](https://github.com/wycats/handlebars.js/issues/469) - Add support for `?` in ids
79
- Docs updates
810

911
[Commits](https://github.com/wycats/handlebars.js/compare/v1.0.11...master)

spec/parser_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ def path(*parts)
125125

126126
it "parses simple mustaches" do
127127
ast_for("{{foo}}").should == root { mustache id("foo") }
128+
ast_for("{{foo?}}").should == root { mustache id("foo?") }
129+
ast_for("{{foo_}}").should == root { mustache id("foo_") }
130+
ast_for("{{foo-}}").should == root { mustache id("foo-") }
131+
ast_for("{{foo:}}").should == root { mustache id("foo:") }
128132
end
129133

130134
it "parses simple mustaches with data" do

src/handlebars.l

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<mu>"{{" { return 'OPEN'; }
3333

3434
<mu>"=" { return 'EQUALS'; }
35-
<mu>"."/[}/ ] { return 'ID'; }
35+
<mu>"."/[}\/ ] { return 'ID'; }
3636
<mu>".." { return 'ID'; }
3737
<mu>[\/.] { return 'SEP'; }
3838
<mu>\s+ { /*ignore whitespace*/ }
@@ -44,7 +44,18 @@
4444
<mu>"true"/[}\s] { return 'BOOLEAN'; }
4545
<mu>"false"/[}\s] { return 'BOOLEAN'; }
4646
<mu>\-?[0-9]+/[}\s] { return 'INTEGER'; }
47-
<mu>[a-zA-Z0-9_$:\-]+/[=}\s\/.] { return 'ID'; }
47+
48+
/*
49+
ID is the inverse of control characters.
50+
Control characters ranges:
51+
[\s] Whitespace
52+
[!"#%-,\./] !, ", #, %, &, ', (, ), *, +, ,, ., /, Exceptions in range: $, -
53+
[;->@] ;, <, =, >, @, Exceptions in range: :, ?
54+
[\[-\^`] [, \, ], ^, `, Exceptions in range: _
55+
[\{-~] {, |, }, ~
56+
*/
57+
<mu>[^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.] { return 'ID'; }
58+
4859
<mu>'['[^\]]*']' { yytext = yytext.substr(1, yyleng-2); return 'ID'; }
4960
<mu>. { return 'INVALID'; }
5061
<par>\s+ { /*ignore whitespace*/ }

0 commit comments

Comments
 (0)