Skip to content

Commit 3bd5344

Browse files
committed
Enforcing that the manifest keys NEVER start with "/"
1 parent acc4187 commit 3bd5344

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/WebpackConfig.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ class WebpackConfig {
107107
}
108108

109109
setManifestKeyPrefix(manifestKeyPrefix) {
110+
/*
111+
* Normally, we make sure that the manifest keys don't start
112+
* with an opening "/" ever... for consistency. If you need
113+
* to manually specify the manifest key (e.g. because you're
114+
* publicPath is absolute), we're *still* adding this restriction,
115+
* to help avoid a user accidentally adding an opening "/"
116+
* and changing their keys from what they looked like before.
117+
*/
118+
if (manifestKeyPrefix.indexOf('/') === 0) {
119+
throw new Error(`For consistency, the value passed to setManifestKeyPrefix() cannot start with "/". Try setManifestKeyPrefix('${manifestKeyPrefix.replace(/^\//, '')}') instead.`);
120+
}
121+
110122
// guarantee a single trailing slash, except for blank strings
111123
if (manifestKeyPrefix !== '') {
112124
manifestKeyPrefix = manifestKeyPrefix.replace(/\/$/, '');

test/WebpackConfig.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ describe('WebpackConfig object', () => {
148148

149149
it('You can set it!', () => {
150150
const config = createConfig();
151-
config.setManifestKeyPrefix('/foo');
151+
config.setManifestKeyPrefix('foo');
152152

153153
// trailing slash added
154-
expect(config.manifestKeyPrefix).to.equal('/foo/');
154+
expect(config.manifestKeyPrefix).to.equal('foo/');
155155
});
156156

157157
it('You can set it blank', () => {
@@ -161,6 +161,14 @@ describe('WebpackConfig object', () => {
161161
// trailing slash not added
162162
expect(config.manifestKeyPrefix).to.equal('');
163163
});
164+
165+
it('You cannot use an opening slash', () => {
166+
const config = createConfig();
167+
168+
expect(() => {
169+
config.setManifestKeyPrefix('/foo/');
170+
}).to.throw('the value passed to setManifestKeyPrefix() cannot start with "/"');
171+
});
164172
});
165173

166174
describe('addEntry', () => {

0 commit comments

Comments
 (0)