Skip to content

Commit

Permalink
fix: replace url-join with path.posix.join, fixes webpack#333
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang committed Sep 21, 2018
1 parent 0f9e2e7 commit 2f05473
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const mime = require('mime');
const urlJoin = require('url-join');
const DevMiddlewareError = require('./DevMiddlewareError');
const { getFilenameFromUrl, handleRangeHeaders, handleRequest, ready } = require('./util');

Expand Down Expand Up @@ -52,7 +52,7 @@ module.exports = function wrapper(context) {
throw new DevMiddlewareError('next');
}

filename = urlJoin(filename, index);
filename = path.posix.join(filename, index);
stat = context.fs.statSync(filename);
if (!stat.isFile()) {
throw new DevMiddlewareError('next');
Expand Down
5 changes: 2 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require('path');
const { parse } = require('url');
const querystring = require('querystring');
const parseRange = require('range-parser');
const urlJoin = require('url-join');

const HASH_REGEXP = /[0-9a-f]{10,}/;

Expand Down Expand Up @@ -92,7 +91,7 @@ module.exports = {
if (process.platform === 'win32') {
// Path Handling for Microsoft Windows
if (filename) {
uri = urlJoin((outputPath || ''), querystring.unescape(filename));
uri = path.posix.join((outputPath || ''), querystring.unescape(filename));

if (!path.win32.isAbsolute(uri)) {
uri = `/${uri}`;
Expand All @@ -104,7 +103,7 @@ module.exports = {

// Path Handling for all other operating systems
if (filename) {
uri = urlJoin((outputPath || ''), filename);
uri = path.posix.join((outputPath || ''), filename);

if (!path.posix.isAbsolute(uri)) {
uri = `/${uri}`;
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"memory-fs": "~0.4.1",
"mime": "^2.3.1",
"range-parser": "^1.0.3",
"url-join": "^4.0.0",
"webpack-log": "^2.0.0"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions test/tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ describe('GetFilenameFromUrl', () => {
outputPath: '/root',
publicPath: '/test/',
expected: '/root/sample.txt'
},
{
url: '/test/sample.txt',
outputPath: '/test/#leadinghash',
publicPath: '/',
expected: '/test/#leadinghash/test/sample.txt'
}
];

Expand Down

0 comments on commit 2f05473

Please sign in to comment.