Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(getRootUrl)!: If not configured use first subdirectory as webroot instead of last #570

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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