From 0bb2ad967a373a2a74d494e3616144c2206675e7 Mon Sep 17 00:00:00 2001 From: Patrick Haug Date: Mon, 19 Nov 2018 23:26:22 +0100 Subject: [PATCH] fix(server): exclude http and https from regex (#155) * Exclude http and https from regex. Should fix #153 * Fix regex whitespace and simplify * Add test for joinURLPath --- packages/server/src/util.js | 3 ++- packages/server/src/util.test.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/util.test.js diff --git a/packages/server/src/util.js b/packages/server/src/util.js index 0eb8dbce..74de06ea 100644 --- a/packages/server/src/util.js +++ b/packages/server/src/util.js @@ -9,4 +9,5 @@ export const smartRequire = modulePath => { return require(modulePath) } -export const joinURLPath = (...paths) => paths.join('/').replace(/\/\//g, '/') +export const joinURLPath = (...paths) => + paths.join('/').replace(/(? { + describe('#joinURLPath', () => { + it('should join paths with relative public path', () => { + expect(joinURLPath('public', 'style.css')).toBe('public/style.css') + expect(joinURLPath('public/', 'style.css')).toBe('public/style.css') + }) + it('should join paths with absolute public path', () => { + const publicPath = 'http://localhost:3001/public' + + expect(joinURLPath(publicPath, 'style.css')).toBe( + `${publicPath}/style.css`, + ) + expect(joinURLPath(`${publicPath}/`, 'style.css')).toBe( + `${publicPath}/style.css`, + ) + }) + }) +})