Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow a custom escapeExpression for an env #1523

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function template(templateSpec, env) {
return typeof current === 'function' ? current.call(context) : current;
},

escapeExpression: Utils.escapeExpression,
escapeExpression: env.escapeExpression || Utils.escapeExpression,
invokePartial: invokePartialWrapper,

fn: function(i) {
Expand Down
10 changes: 10 additions & 0 deletions spec/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ describe('basic context', function() {
'escaping should properly handle amperstands');
});

it('escaping with escapeExpressions override', function() {
global.handlebarsEnv.escapeExpression = s => s.replace('&', 'AND');
shouldCompileTo('{{awesome}}', {awesome: 'x&y'}, 'xANDy', 'text is escaped using the custom escapeExpression function');
});

it('falls back to the default escapeExpressions', function() {
global.handlebarsEnv.escapeExpression = null;
shouldCompileTo('{{awesome}}', {awesome: 'x&y'}, 'x&y', 'text is escaped using the standard escapeExpression function');
});

it("functions returning safestrings shouldn't be escaped", function() {
var hash = {awesome: function() { return new Handlebars.SafeString('&\'\\<>'); }};
shouldCompileTo('{{awesome}}', hash, '&\'\\<>',
Expand Down