Skip to content

Commit

Permalink
Merge pull request #161 from assemble-main/politics-rewired/hotfix-es…
Browse files Browse the repository at this point in the history
…cape-regex-string

escape regex string before custom fields replacement
  • Loading branch information
bchrobot authored May 22, 2019
2 parents cb78f0c + 2de65ef commit 2e8cbe4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ export const applyScript = ({ script, contact, customFields, texter }) => {
let appliedScript = script;

for (const field of scriptFields) {
const re = new RegExp(`${delimit(field)}`, "g");
const re = new RegExp(escapeRegExp(`${delimit(field)}`), "g");
appliedScript = appliedScript.replace(
re,
getScriptFieldValue(contact, texter, field)
);
}
return appliedScript;
};

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

0 comments on commit 2e8cbe4

Please sign in to comment.