Skip to content

Commit

Permalink
fix(link): Don't rewrite links with fileId inside Collectives
Browse files Browse the repository at this point in the history
Required to allow relative links (and those without origin) to other
collectives pages to be resolved by link previews.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Feb 20, 2024
1 parent 10cfd6a commit b980f87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/helpers/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
*/

import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'

const absolutePath = function(base, rel) {
Expand Down Expand Up @@ -61,6 +62,10 @@ const domHref = function(node, relativePath) {
if (ref.startsWith('#')) {
return ref
}
// Don't rewrite URL in Collectives context
if (loadState('core', 'active-app') === 'collectives') {
return ref
}

const match = ref.match(/^([^?]*)\?fileId=(\d+)/)
if (match) {
Expand Down
15 changes: 15 additions & 0 deletions src/tests/helpers/links.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { domHref, parseHref } from '../../helpers/links'
import { loadState } from '@nextcloud/initial-state'

global.OCA = {
Viewer: {
Expand All @@ -12,6 +13,9 @@ global.OC = {

global._oc_webroot = ''

jest.mock('@nextcloud/initial-state')
loadState.mockImplementation((app, key) => 'files')

describe('Preparing href attributes for the DOM', () => {

test('leave empty hrefs alone', () => {
Expand Down Expand Up @@ -103,3 +107,14 @@ describe('Inserting hrefs into the dom and extracting them again', () => {
})

})

describe('Preparing href attributes for the DOM in Collectives app', () => {
beforeAll(() => {
loadState.mockImplementation((app, key) => 'collectives')
})

test('relative link with fileid in Collectives', () => {
expect(domHref({attrs: {href: 'otherfile?fileId=123'}}))
.toBe('otherfile?fileId=123')
})
})

0 comments on commit b980f87

Please sign in to comment.