diff --git a/lib/middleware.js b/lib/middleware.js index 23e2220cf..407b02c81 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -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'); @@ -51,7 +51,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'); diff --git a/lib/util.js b/lib/util.js index 1ca5437ee..582218179 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,10 +1,10 @@ 'use strict'; +const path = require('path'); const { parse } = require('url'); const querystring = require('querystring'); const pathabs = require('path-is-absolute'); const parseRange = require('range-parser'); -const urlJoin = require('url-join'); const HASH_REGEXP = /[0-9a-f]{10,}/; @@ -92,7 +92,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 (!pathabs.win32(uri)) { uri = `/${uri}`; @@ -104,7 +104,7 @@ module.exports = { // Path Handling for all other operating systems if (filename) { - uri = urlJoin((outputPath || ''), filename); + uri = path.posix.join((outputPath || ''), filename); if (!pathabs.posix(uri)) { uri = `/${uri}`; diff --git a/package.json b/package.json index cedf34803..fd0a1131e 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "mime": "^2.3.1", "path-is-absolute": "^1.0.0", "range-parser": "^1.0.3", - "url-join": "^4.0.0", "webpack-log": "^2.0.0" }, "devDependencies": { diff --git a/test/tests/util.js b/test/tests/util.js index c6bafe85f..ce7815345 100644 --- a/test/tests/util.js +++ b/test/tests/util.js @@ -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' } ];