Skip to content

Commit

Permalink
Fix InterpolateHtmlPlugin only replacing the first occurrence (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
fson authored and gaearon committed Sep 23, 2016
1 parent 500fb74 commit e41d671
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/react-dev-utils/InterpolateHtmlPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// https://github.com/ampedandwired/html-webpack-plugin#events

'use strict';
const escapeStringRegexp = require('escape-string-regexp');

class InterpolateHtmlPlugin {
constructor(replacements) {
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"dependencies": {
"chalk": "1.1.3",
"escape-string-regexp": "1.0.5",
"opn": "4.0.2"
},
"peerDependencies": {
Expand Down

0 comments on commit e41d671

Please sign in to comment.