From 0b3f4ef6042e416e5972b7e19ab26414b0696b39 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 20 Feb 2024 20:20:58 +0100 Subject: [PATCH] fix(NcReferenceList): Resolve relative URLs before fetching references Resolve relative URLs and those without a location using `window.location` before fetching references for them. This fixes e.g. getting references for relative links to other pages in Collectives. Signed-off-by: Jonas --- src/components/NcRichText/NcReferenceList.vue | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/NcRichText/NcReferenceList.vue b/src/components/NcRichText/NcReferenceList.vue index f01abc7c7f..698f1ff5d5 100644 --- a/src/components/NcRichText/NcReferenceList.vue +++ b/src/components/NcRichText/NcReferenceList.vue @@ -82,6 +82,9 @@ export default { richObjectType: 'open-graph', } }, + fullUrl() { + return new URL(this.text.trim(), window.location) + }, }, watch: { text: 'fetch', @@ -97,7 +100,7 @@ export default { return } - if (!(new RegExp(URL_PATTERN).exec(this.text))) { + if (!(new RegExp(URL_PATTERN).exec(this.fullUrl.href))) { this.loading = false return } @@ -113,7 +116,7 @@ export default { }) }, resolve() { - const match = (new RegExp(URL_PATTERN).exec(this.text.trim())) + const match = (new RegExp(URL_PATTERN).exec(this.fullUrl.href)) if (this.limit === 1 && match) { return axios.get(generateOcsUrl('references/resolve', 2) + `?reference=${encodeURIComponent(match[0])}`) }