Skip to content

Commit 08207cc

Browse files
authored
On windows path spaces should resolve to %20 (#288)
* fixes #284, on windows path spaces should resolve to %20 * disable linting failures temporarily * try out windows webpack config * some output for debugging * adjusting tests for windows * tests for bugfix passing, removing debugging statements * turning on all the tests * coverage tweaks, since coverage doesn't run on windows
1 parent d26c67c commit 08207cc

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/util.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = {
6565
const localPrefix = parse(publicPath || '/', false, true);
6666
const urlObject = parse(url);
6767
let filename;
68+
let result = '';
6869

6970
// publicPath has the hostname that is not the same as request url's, should fail
7071
if (localPrefix.hostname !== null && urlObject.hostname !== null &&
@@ -99,7 +100,15 @@ module.exports = {
99100
}
100101

101102
// if no matches, use outputPath as filename
102-
return querystring.unescape(uri);
103+
result = querystring.unescape(uri);
104+
105+
// fixes #284, on windows path spaces should resolve to %20
106+
/* istanbul ignore if */
107+
if (process.platform === 'win32') {
108+
result = result.replace(/\s/g, '%20');
109+
}
110+
111+
return result;
103112
},
104113

105114
handleRangeHeaders(content, req, res) {

test/tests/util.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const assert = require('assert');
44
const { getFilenameFromUrl } = require('../../lib/util');
55

6+
const isWindows = process.platform === 'win32';
7+
68
function testUrl(options) {
79
const url = getFilenameFromUrl(options.publicPath, options, options.url);
810
assert.equal(url, options.expected);
@@ -119,7 +121,8 @@ describe('GetFilenameFromUrl', () => {
119121
url: '/pathname%20with%20spaces.js',
120122
outputPath: '/',
121123
publicPath: '/',
122-
expected: '/pathname with spaces.js'
124+
// ref #284 - windows paths should persist %20
125+
expected: isWindows ? '/pathname%20with%20spaces.js' : '/pathname with spaces.js'
123126
},
124127
{
125128
url: '/test/windows.txt',
@@ -275,4 +278,18 @@ describe('GetFilenameFromUrl', () => {
275278
testUrl(test);
276279
});
277280
}
281+
282+
if (isWindows) {
283+
// explicit test for #284
284+
const test = {
285+
url: '/test/windows.txt',
286+
outputPath: 'C:\\My%20Path\\wwwroot',
287+
publicPath: '/test',
288+
expected: 'C://\\My%20Path\\wwwroot/windows.txt'
289+
};
290+
291+
it(`windows: should process ${test.url} -> ${test.expected}`, () => {
292+
testUrl(test);
293+
});
294+
}
278295
});

0 commit comments

Comments
 (0)