Skip to content

Commit

Permalink
fix: escape property names in compat mode (handlebars-lang#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp authored and bitwiseman committed May 18, 2021
1 parent 70d19e7 commit 30e3ed9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/handlebars/compiler/javascript-compiler.js
Expand Up @@ -28,7 +28,12 @@ JavaScriptCompiler.prototype = {
}
},
depthedLookup: function(name) {
return [this.aliasable('this.lookup'), '(depths, "', name, '")'];
return [
this.aliasable('this.lookup'),
'(depths, ',
JSON.stringify(name),
')'
];
},

compilerInfo: function() {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions spec/security.js
Expand Up @@ -99,4 +99,26 @@ describe('security issues', function() {
shouldCompileTo('{{lookup this "__proto__"}}', {}, '');
});
});

describe('escapes template variables', function() {
it('in compat mode', function() {
expectTemplate("{{'a\\b'}}")
.withCompileOptions({ compat: true })
.withInput({ 'a\\b': 'c' })
.toCompileTo('c');
});

it('in default mode', function() {
expectTemplate("{{'a\\b'}}")
.withCompileOptions()
.withInput({ 'a\\b': 'c' })
.toCompileTo('c');
});
it('in default mode', function() {
expectTemplate("{{'a\\b'}}")
.withCompileOptions({ strict: true })
.withInput({ 'a\\b': 'c' })
.toCompileTo('c');
});
});
});

0 comments on commit 30e3ed9

Please sign in to comment.