Skip to content

Commit

Permalink
Escape keys as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Hanlon committed Jan 19, 2018
1 parent c8b8ac6 commit 1122103
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/server/views/helpers/handlebars.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
const _ = require('lodash');
const Handlebars = require('handlebars');

const replacer = (key, value) =>
_.isString(value) ? Handlebars.Utils.escapeExpression(value) : value;
const { SafeString, Util: { escapeExpression } } = Handlebars;

const replacer = (key, value) => {
if (_.isObject(value)) {
return _.transform(value, (result, v, k) => {
result[escapeExpression(k)] = v;
});
} else if (_.isString(value)) {
return escapeExpression(value);
} else {
return value;
}
}

const helpers = {
json(obj, pretty = false) {
const args = [obj, replacer];
if (pretty) {
args.push(2);
}
return new Handlebars.SafeString(JSON.stringify(...args));
return new SafeString(JSON.stringify(...args));
},

adjustedPage(currentPage, pageSize, newPageSize) {
Expand Down

0 comments on commit 1122103

Please sign in to comment.