Skip to content

Commit

Permalink
Merge pull request #566 from nextcloud-libraries/fix/generate-filepat…
Browse files Browse the repository at this point in the history
…h-type

fix: Adjust `generateFilePath` to include `type` also for `index.php`
  • Loading branch information
susnux committed Jan 29, 2024
2 parents 1a4ccc4 + b47d7fc commit 3f8327e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions __tests__/paths.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ describe('Path generation', () => {
expect(generateFilePath('forms', '', 'index.php')).toBe('/index.php/apps/forms')
})

// TODO: This feels wrong, I would expect `/index.php/apps/forms/templates`
test('non core PHP index files with type', () => {
expect(generateFilePath('forms', 'templates', 'index.php')).toBe('/index.php/apps/forms')
expect(generateFilePath('forms', 'templates', 'index.php')).toBe('/index.php/apps/forms/templates')
})

test('non core PHP file', () => {
Expand Down
11 changes: 5 additions & 6 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ export const generateFilePath = (app: string, type: string, file: string) => {
const isCore = window?.OC?.coreApps?.indexOf(app) !== -1
let link = getRootUrl()
if (file.substring(file.length - 3) === 'php' && !isCore) {
link += '/index.php/apps/' + app
link += `/index.php/apps/${app}`
if (type) {
link += `/${encodeURI(type)}`
}
if (file !== 'index.php') {
link += '/'
if (type) {
link += encodeURI(type + '/')
}
link += file
link += `/${file}`
}
} else if (file.substring(file.length - 3) !== 'php' && !isCore) {
link = getAppRootUrl(app)
Expand Down

0 comments on commit 3f8327e

Please sign in to comment.