From e41d671beef4338b70f38684ee393109f85caf39 Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Sat, 24 Sep 2016 02:28:32 +0300 Subject: [PATCH] Fix InterpolateHtmlPlugin only replacing the first occurrence (#731) Fixes https://github.com/facebookincubator/create-react-app/issues/625#issuecomment-249320724. --- packages/react-dev-utils/InterpolateHtmlPlugin.js | 6 +++++- packages/react-dev-utils/package.json | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-dev-utils/InterpolateHtmlPlugin.js b/packages/react-dev-utils/InterpolateHtmlPlugin.js index 6ac587b3dc9..07558f47830 100644 --- a/packages/react-dev-utils/InterpolateHtmlPlugin.js +++ b/packages/react-dev-utils/InterpolateHtmlPlugin.js @@ -16,6 +16,7 @@ // https://github.com/ampedandwired/html-webpack-plugin#events 'use strict'; +const escapeStringRegexp = require('escape-string-regexp'); class InterpolateHtmlPlugin { constructor(replacements) { @@ -29,7 +30,10 @@ class InterpolateHtmlPlugin { // Run HTML through a series of user-specified string replacements. Object.keys(this.replacements).forEach(key => { const value = this.replacements[key]; - data.html = data.html.replace('%' + key + '%', value); + data.html = data.html.replace( + new RegExp('%' + escapeStringRegexp(key) + '%', 'g'), + value + ); }); callback(null, data); } diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index 515515f70fd..f0bf110b3a4 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -22,6 +22,7 @@ ], "dependencies": { "chalk": "1.1.3", + "escape-string-regexp": "1.0.5", "opn": "4.0.2" }, "peerDependencies": {