diff --git a/lib/middleware.js b/lib/middleware.js index 2813bd6ab..602632b65 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'); @@ -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'); diff --git a/lib/util.js b/lib/util.js index bce5f9f5c..e8a70beff 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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,}/; @@ -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}`; @@ -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}`; diff --git a/package.json b/package.json index c523cc42d..16ea80767 100644 --- a/package.json +++ b/package.json @@ -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": { 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' } ];