From b980f87bb4c02e6eea8e3a2c5b30c81f15c2aede Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 20 Feb 2024 20:17:23 +0100 Subject: [PATCH] fix(link): Don't rewrite links with fileId inside Collectives Required to allow relative links (and those without origin) to other collectives pages to be resolved by link previews. Signed-off-by: Jonas --- src/helpers/links.js | 5 +++++ src/tests/helpers/links.spec.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/helpers/links.js b/src/helpers/links.js index 7ec077b008..b45ab1ba7e 100644 --- a/src/helpers/links.js +++ b/src/helpers/links.js @@ -20,6 +20,7 @@ * */ +import { loadState } from '@nextcloud/initial-state' import { generateUrl } from '@nextcloud/router' const absolutePath = function(base, rel) { @@ -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) { diff --git a/src/tests/helpers/links.spec.js b/src/tests/helpers/links.spec.js index dac80a9a59..12d4e61460 100644 --- a/src/tests/helpers/links.spec.js +++ b/src/tests/helpers/links.spec.js @@ -1,4 +1,5 @@ import { domHref, parseHref } from '../../helpers/links' +import { loadState } from '@nextcloud/initial-state' global.OCA = { Viewer: { @@ -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', () => { @@ -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') + }) +})