Commit e41d671b authored by Ville Immonen's avatar Ville Immonen Committed by Dan Abramov
Browse files

Fix InterpolateHtmlPlugin only replacing the first occurrence (#731)

Fixes https://github.com/facebookincubator/create-react-app/issues/625#issuecomment-249320724.
parent 500fb749
Showing with 6 additions and 1 deletion
+6 -1
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
// https://github.com/ampedandwired/html-webpack-plugin#events // https://github.com/ampedandwired/html-webpack-plugin#events
'use strict'; 'use strict';
const escapeStringRegexp = require('escape-string-regexp');
class InterpolateHtmlPlugin { class InterpolateHtmlPlugin {
constructor(replacements) { constructor(replacements) {
...@@ -29,7 +30,10 @@ class InterpolateHtmlPlugin { ...@@ -29,7 +30,10 @@ class InterpolateHtmlPlugin {
// Run HTML through a series of user-specified string replacements. // Run HTML through a series of user-specified string replacements.
Object.keys(this.replacements).forEach(key => { Object.keys(this.replacements).forEach(key => {
const value = this.replacements[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); callback(null, data);
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
], ],
"dependencies": { "dependencies": {
"chalk": "1.1.3", "chalk": "1.1.3",
"escape-string-regexp": "1.0.5",
"opn": "4.0.2" "opn": "4.0.2"
}, },
"peerDependencies": { "peerDependencies": {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment