Skip to content

Commit f058970

Browse files
committedFeb 13, 2021
fix: escape property names in compat mode (#1736)
1 parent 77825f8 commit f058970

File tree

3 files changed

+40
-630
lines changed

3 files changed

+40
-630
lines changed
 

‎lib/handlebars/compiler/javascript-compiler.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ JavaScriptCompiler.prototype = {
1616
return this.internalNameLookup(parent, name);
1717
},
1818
depthedLookup: function(name) {
19-
return [this.aliasable('container.lookup'), '(depths, "', name, '")'];
19+
return [
20+
this.aliasable('container.lookup'),
21+
'(depths, ',
22+
JSON.stringify(name),
23+
')'
24+
];
2025
},
2126

2227
compilerInfo: function() {

‎package-lock.json

+12-629
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎spec/security.js

+22
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,28 @@ describe('security issues', function() {
396396
});
397397
});
398398
});
399+
400+
describe('escapes template variables', function() {
401+
it('in compat mode', function() {
402+
expectTemplate("{{'a\\b'}}")
403+
.withCompileOptions({ compat: true })
404+
.withInput({ 'a\\b': 'c' })
405+
.toCompileTo('c');
406+
});
407+
408+
it('in default mode', function() {
409+
expectTemplate("{{'a\\b'}}")
410+
.withCompileOptions()
411+
.withInput({ 'a\\b': 'c' })
412+
.toCompileTo('c');
413+
});
414+
it('in default mode', function() {
415+
expectTemplate("{{'a\\b'}}")
416+
.withCompileOptions({ strict: true })
417+
.withInput({ 'a\\b': 'c' })
418+
.toCompileTo('c');
419+
});
420+
});
399421
});
400422

401423
function wrapToAdjustContainer(precompiledTemplateFunction) {

0 commit comments

Comments
 (0)
Please sign in to comment.