1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-03 08:45:40 +02:00

fix double slash on buildURL (#615)

This commit is contained in:
Scott Bishel 2021-06-22 09:26:00 -06:00 committed by GitHub
parent 1f7470aca7
commit c86d9b9ff5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -34,4 +34,36 @@ describe('utils', () => {
windowAsAny.openInNewBrowser = null
})
})
describe('test - buildURL', () => {
test('buildURL, no base', () => {
expect(Utils.buildURL('test', true)).toBe('http://localhost/test')
expect(Utils.buildURL('/test', true)).toBe('http://localhost/test')
expect(Utils.buildURL('test')).toBe('/test')
expect(Utils.buildURL('/test')).toBe('/test')
})
test('buildURL, base no slash', () => {
const windowAsAny = window as any
windowAsAny.baseURL = 'base'
expect(Utils.buildURL('test', true)).toBe('http://localhost/base/test')
expect(Utils.buildURL('/test', true)).toBe('http://localhost/base/test')
expect(Utils.buildURL('test')).toBe('base/test')
expect(Utils.buildURL('/test')).toBe('base/test')
})
test('buildUrl, base with slash', () => {
const windowAsAny = window as any
windowAsAny.baseURL = '/base/'
expect(Utils.buildURL('test', true)).toBe('http://localhost/base/test')
expect(Utils.buildURL('/test', true)).toBe('http://localhost/base/test')
expect(Utils.buildURL('test')).toBe('base/test')
expect(Utils.buildURL('/test')).toBe('base/test')
})
})
})

View File

@ -333,6 +333,9 @@ class Utils {
finalPath = baseURL + '/' + path
}
if (absolute) {
if (finalPath.indexOf('/') === 0) {
finalPath = finalPath.slice(1)
}
return window.location.origin + '/' + finalPath
}
return finalPath