Skip to content

Commit 7a2109f

Browse files
committed
fix(getRootUrl)!: If not configured use first subdirectory as webroot instead of last
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 3f8327e commit 7a2109f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

__tests__/webroot.spec.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,25 @@ describe('Web root handling', () => {
5757
expect(getBaseUrl()).toBe(`${window.location.origin}/nextcloud`)
5858
})
5959

60-
// TODO: This seems to be wrong, would expect `/nextcloud`
60+
test('with implicit empty web root', () => {
61+
window._oc_webroot = undefined
62+
window.location.pathname = '/'
63+
expect(getRootUrl()).toBe('/')
64+
expect(getBaseUrl()).toBe(`${window.location.origin}/`)
65+
})
66+
6167
test('with implicit web root and path rename', () => {
68+
window._oc_webroot = undefined
69+
window.location.pathname = '/nextcloud'
70+
expect(getRootUrl()).toBe('/nextcloud')
71+
expect(getBaseUrl()).toBe(`${window.location.origin}/nextcloud`)
72+
})
73+
74+
test('with implicit web root on route with path rename', () => {
6275
window._oc_webroot = undefined
6376
window.location.pathname = '/nextcloud/apps/files'
64-
expect(getRootUrl()).toBe('/nextcloud/apps')
65-
expect(getBaseUrl()).toBe(`${window.location.origin}/nextcloud/apps`)
77+
expect(getRootUrl()).toBe('/nextcloud')
78+
expect(getBaseUrl()).toBe(`${window.location.origin}/nextcloud`)
6679
})
6780
})
6881

lib/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ export function getRootUrl(): string {
227227
if (pos !== -1) {
228228
webroot = webroot.slice(0, pos)
229229
} else {
230-
webroot = webroot.slice(0, webroot.lastIndexOf('/'))
230+
const index = webroot.indexOf('/', 1)
231+
// Make sure to not cut end of path if there is just the webroot like `/nextcloud`
232+
webroot = webroot.slice(0, index > 0 ? index : undefined)
231233
}
232234
}
233235
return webroot

0 commit comments

Comments
 (0)