Skip to content

Commit 38516d0

Browse files
committed
Enforcing that the manifest keys NEVER start with "/"
1 parent 4ad8d88 commit 38516d0

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 0.12.0
4+
5+
* The `setManifestKeyPrefix()` method now forbids the key to
6+
start with a `/` - #105.
7+
38
## 0.11.0
49

510
* The `webpack` package was upgraded from version 2.2 to 3.1 #53. The

lib/WebpackConfig.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ class WebpackConfig {
113113
}
114114

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

test/WebpackConfig.js

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

120120
it('You can set it!', () => {
121121
const config = createConfig();
122-
config.setManifestKeyPrefix('/foo');
122+
config.setManifestKeyPrefix('foo');
123123

124124
// trailing slash added
125-
expect(config.manifestKeyPrefix).to.equal('/foo/');
125+
expect(config.manifestKeyPrefix).to.equal('foo/');
126126
});
127127

128128
it('You can set it blank', () => {
@@ -132,6 +132,14 @@ describe('WebpackConfig object', () => {
132132
// trailing slash not added
133133
expect(config.manifestKeyPrefix).to.equal('');
134134
});
135+
136+
it('You cannot use an opening slash', () => {
137+
const config = createConfig();
138+
139+
expect(() => {
140+
config.setManifestKeyPrefix('/foo/');
141+
}).to.throw('the value passed to setManifestKeyPrefix() cannot start with "/"');
142+
});
135143
});
136144

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

0 commit comments

Comments
 (0)