Skip to content

Commit 3315df5

Browse files
nknappbitwiseman
authored andcommitted
fix: escape property names in compat mode (handlebars-lang#1736)
1 parent e61e016 commit 3315df5

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
@@ -103,4 +103,26 @@ describe('security issues', function() {
103103
shouldCompileTo('{{lookup this "__proto__"}}', {}, '');
104104
});
105105
});
106+
107+
describe('escapes template variables', function() {
108+
it('in compat mode', function() {
109+
expectTemplate("{{'a\\b'}}")
110+
.withCompileOptions({ compat: true })
111+
.withInput({ 'a\\b': 'c' })
112+
.toCompileTo('c');
113+
});
114+
115+
it('in default mode', function() {
116+
expectTemplate("{{'a\\b'}}")
117+
.withCompileOptions()
118+
.withInput({ 'a\\b': 'c' })
119+
.toCompileTo('c');
120+
});
121+
it('in default mode', function() {
122+
expectTemplate("{{'a\\b'}}")
123+
.withCompileOptions({ strict: true })
124+
.withInput({ 'a\\b': 'c' })
125+
.toCompileTo('c');
126+
});
127+
});
106128
});

0 commit comments

Comments
 (0)