From 9278b8bdf8187c2562a68c96b1b9bccae27a4ff9 Mon Sep 17 00:00:00 2001 From: stefano bovio Date: Mon, 29 May 2017 09:25:05 +0200 Subject: [PATCH] Fix #1880 search fails on ie (#1881) --- web/client/utils/TemplateUtils.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/web/client/utils/TemplateUtils.js b/web/client/utils/TemplateUtils.js index b94a742aa7..54ff2bbed7 100644 --- a/web/client/utils/TemplateUtils.js +++ b/web/client/utils/TemplateUtils.js @@ -6,6 +6,8 @@ * LICENSE file in the root directory of this source tree. */ +const {isString} = require('lodash'); + module.exports = { /** * generates a template string to use for static replacements. @@ -20,15 +22,17 @@ module.exports = { var fn = cache[template]; if (!fn) { - // Replace ${expressions} (etc) with ${map.expressions}. - let sanitized = template - .replace(/\$\{([\s]*[^;\s\{]+[\s]*)\}/g, function(_, match) { - return `\$\{map.${match.trim()}\}`; - }) - // Afterwards, replace anything that's not ${map.expressions}' (etc) with a blank string. - .replace(/(\$\{(?!map\.)[^}]+\})/g, ''); - - fn = Function('map', `return \`${sanitized}\``); + fn = (map) => { + + let sanitized = template + .replace(/\$\{([\s]*[^;\s\{]+[\s]*)\}/g, (_, match) => { + return match.trim().split(".").reduce((a, b) => { + return a && a[b]; + }, map); + }); + + return isString(sanitized) && sanitized || ''; + }; cache[template] = fn; }