Skip to content

Commit 0bb2ad9

Browse files
patrickhauggregberge
authored andcommitted
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
1 parent 2af8cf6 commit 0bb2ad9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/server/src/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const smartRequire = modulePath => {
99
return require(modulePath)
1010
}
1111

12-
export const joinURLPath = (...paths) => paths.join('/').replace(/\/\//g, '/')
12+
export const joinURLPath = (...paths) =>
13+
paths.join('/').replace(/(?<!:)\/\//g, '/')

packages/server/src/util.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { joinURLPath } from './util'
2+
3+
describe('util', () => {
4+
describe('#joinURLPath', () => {
5+
it('should join paths with relative public path', () => {
6+
expect(joinURLPath('public', 'style.css')).toBe('public/style.css')
7+
expect(joinURLPath('public/', 'style.css')).toBe('public/style.css')
8+
})
9+
it('should join paths with absolute public path', () => {
10+
const publicPath = 'http://localhost:3001/public'
11+
12+
expect(joinURLPath(publicPath, 'style.css')).toBe(
13+
`${publicPath}/style.css`,
14+
)
15+
expect(joinURLPath(`${publicPath}/`, 'style.css')).toBe(
16+
`${publicPath}/style.css`,
17+
)
18+
})
19+
})
20+
})

0 commit comments

Comments
 (0)