Skip to content

Commit 955e53e

Browse files
Sean Middleditchshellscape
authored andcommitted
Fix Windows Paths (#276)
* fixes #270: bad filename generation Uses an existing dependency in the module to test if the generated filename is absolute before adding the leading slash. This is the most minimal fix for the Windows incompatibility that doesn't break a bunch of test cases that currently pass on Windows, and which won't run afoul of the filesystem abstraction layer used by Webpack. * Tests for #270 * Code style adherence * Attempt to appease the Linux spirits The pathabs call wasn't treating c:\ as absolute on Linux, so it was still prepending the /, and hence failing out the test. Now instead we call both the posix and win32 versions of the function explicitly, same as is done in the setFs call. That feels dirty to me, but this is already fairly dirty, and I don't think this opens any kind of path attack vector that wasn't already present.
1 parent 843686b commit 955e53e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = {
9393
if (filename) {
9494
uri = urlJoin((outputPath || ''), filename);
9595

96-
if (!uri.startsWith('/')) {
96+
if (!pathabs.posix(uri) && !pathabs.win32(uri)) {
9797
uri = `/${uri}`;
9898
}
9999
}

test/tests/util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ describe('GetFilenameFromUrl', () => {
121121
publicPath: '/',
122122
expected: '/pathname with spaces.js'
123123
},
124+
{
125+
url: '/test/windows.txt',
126+
outputPath: 'c:\\foo',
127+
publicPath: '/test',
128+
// this is weird, but it's legal-ish, and what URI parsing produces
129+
expected: 'c://\\foo/windows.txt'
130+
},
124131
{
125132
url: '/js/sample.js',
126133
compilers: [

0 commit comments

Comments
 (0)