Skip to content

Commit dd2b5c2

Browse files
committed
fix(core): fix url replacement behaviour
1 parent 0b59157 commit dd2b5c2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/smooth-backend-wordpress/src/acf/resolvers/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const endBackslashRegExp = /\/+$/
22

33
export function toRelativeUrl(baseUrl, url) {
44
const regexp = new RegExp(`^${baseUrl.replace(endBackslashRegExp, '')}`)
5-
return `${url.replace(regexp, '')}` || '/'
5+
const finalUrl = `${url.replace(regexp, '')}` || '/'
6+
if (finalUrl.startsWith(':')) return url
7+
return finalUrl
68
}
79

810
function formatDateString(value) {

packages/smooth-backend-wordpress/src/acf/resolvers/util.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,14 @@ describe('util', () => {
7878
),
7979
).toBe('/foo?url=http://smooth-code.com')
8080
})
81+
82+
it('should avoid replacing url containing port', () => {
83+
expect(
84+
toRelativeUrl(
85+
'http://smooth-code.com',
86+
'http://smooth-code.com:8000/foo',
87+
),
88+
).toBe('http://smooth-code.com:8000/foo')
89+
})
8190
})
8291
})

0 commit comments

Comments
 (0)