Skip to content

Commit

Permalink
Fix #1880 search fails on ie (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored and offtherailz committed May 29, 2017
1 parent e184b51 commit 9278b8b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions web/client/utils/TemplateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

}
Expand Down

0 comments on commit 9278b8b

Please sign in to comment.