Skip to content

Commit

Permalink
Merge pull request #5401 from nextcloud/fix/collectives_no_link_rewrite
Browse files Browse the repository at this point in the history
fix(link): Don't rewrite links with fileId inside Collectives
  • Loading branch information
mejo- authored Feb 20, 2024
2 parents 10cfd6a + b980f87 commit c7c93a4
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 c7c93a4

Please sign in to comment.