Skip to content

Commit

Permalink
fix(getRootUrl)!: If not configured use first subdirectory as webroot…
Browse files Browse the repository at this point in the history
… instead of last

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jan 29, 2024
1 parent 3f8327e commit 7a2109f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 16 additions & 3 deletions __tests__/webroot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,25 @@ describe('Web root handling', () => {
expect(getBaseUrl()).toBe(`${window.location.origin}/nextcloud`)
})

// TODO: This seems to be wrong, would expect `/nextcloud`
test('with implicit empty web root', () => {
window._oc_webroot = undefined
window.location.pathname = '/'
expect(getRootUrl()).toBe('/')
expect(getBaseUrl()).toBe(`${window.location.origin}/`)
})

test('with implicit web root and path rename', () => {
window._oc_webroot = undefined
window.location.pathname = '/nextcloud'
expect(getRootUrl()).toBe('/nextcloud')
expect(getBaseUrl()).toBe(`${window.location.origin}/nextcloud`)
})

test('with implicit web root on route with path rename', () => {
window._oc_webroot = undefined
window.location.pathname = '/nextcloud/apps/files'
expect(getRootUrl()).toBe('/nextcloud/apps')
expect(getBaseUrl()).toBe(`${window.location.origin}/nextcloud/apps`)
expect(getRootUrl()).toBe('/nextcloud')
expect(getBaseUrl()).toBe(`${window.location.origin}/nextcloud`)
})
})

Expand Down
4 changes: 3 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export function getRootUrl(): string {
if (pos !== -1) {
webroot = webroot.slice(0, pos)
} else {
webroot = webroot.slice(0, webroot.lastIndexOf('/'))
const index = webroot.indexOf('/', 1)
// Make sure to not cut end of path if there is just the webroot like `/nextcloud`
webroot = webroot.slice(0, index > 0 ? index : undefined)
}
}
return webroot
Expand Down

0 comments on commit 7a2109f

Please sign in to comment.