Skip to content

Commit 30e3ed9

Browse files
nknappbitwiseman
authored andcommitted
fix: escape property names in compat mode (handlebars-lang#1736)
1 parent 70d19e7 commit 30e3ed9

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

lib/handlebars/compiler/javascript-compiler.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ JavaScriptCompiler.prototype = {
2828
}
2929
},
3030
depthedLookup: function(name) {
31-
return [this.aliasable('this.lookup'), '(depths, "', name, '")'];
31+
return [
32+
this.aliasable('this.lookup'),
33+
'(depths, ',
34+
JSON.stringify(name),
35+
')'
36+
];
3237
},
3338

3439
compilerInfo: function() {

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/security.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,26 @@ describe('security issues', function() {
9999
shouldCompileTo('{{lookup this "__proto__"}}', {}, '');
100100
});
101101
});
102+
103+
describe('escapes template variables', function() {
104+
it('in compat mode', function() {
105+
expectTemplate("{{'a\\b'}}")
106+
.withCompileOptions({ compat: true })
107+
.withInput({ 'a\\b': 'c' })
108+
.toCompileTo('c');
109+
});
110+
111+
it('in default mode', function() {
112+
expectTemplate("{{'a\\b'}}")
113+
.withCompileOptions()
114+
.withInput({ 'a\\b': 'c' })
115+
.toCompileTo('c');
116+
});
117+
it('in default mode', function() {
118+
expectTemplate("{{'a\\b'}}")
119+
.withCompileOptions({ strict: true })
120+
.withInput({ 'a\\b': 'c' })
121+
.toCompileTo('c');
122+
});
123+
});
102124
});

0 commit comments

Comments
 (0)