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 974edff commit 5f5ab84
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/server/views/helpers/handlebars.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
const _ = require('lodash');
const Handlebars = require('handlebars');
const _ = require("lodash");
const Handlebars = require("handlebars");

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

const helpers = {
json(obj, pretty = false) {
Expand All @@ -20,18 +29,18 @@ const helpers = {

block(name) {
var blocks = this._blocks;
content = blocks && blocks[name];
return content ? content.join('\n') : null;
content = blocks && blocks[name];
return content ? content.join("\n") : null;
},

contentFor: function(name, options) {
var blocks = this._blocks || (this._blocks = {});
block = blocks[name] || (blocks[name] = []);
block = blocks[name] || (blocks[name] = []);
block.push(options.fn(this));
},

encodeIdAttr: function (id) {
return id.replace(/:| /g, "");
encodeIdAttr: function(id) {
return id.replace(/:| /g, "");
}
};

Expand Down

0 comments on commit 5f5ab84

Please sign in to comment.