From bb3d7288ddf6f721aca5bc396fc91fdc6a31330f Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 21 Nov 2023 10:55:37 +0100 Subject: [PATCH] fix adding x-requested-with header for relative URLs when the base NC URL is empty Signed-off-by: Julien Veyssier --- core/src/utils/xhr-request.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/utils/xhr-request.js b/core/src/utils/xhr-request.js index 66f994246e0..ff8b7641b07 100644 --- a/core/src/utils/xhr-request.js +++ b/core/src/utils/xhr-request.js @@ -21,14 +21,25 @@ import { getRootUrl } from '@nextcloud/router' +/** + * + * @param {string} url the URL to check + * @returns {boolean} + */ +const isRelativeUrl = (url) => { + return !url.startsWith('https://') && !url.startsWith('http://') +} + /** * @param {string} url The URL to check * @return {boolean} true if the URL points to this nextcloud instance */ const isNextcloudUrl = (url) => { const nextcloudBaseUrl = window.location.protocol + '//' + window.location.host + getRootUrl() - // try with relative and absolute URL - return url.startsWith(nextcloudBaseUrl) || url.startsWith(getRootUrl()) + // if the URL is absolute and starts with the baseUrl+rootUrl + // OR if the URL is relative and starts with rootUrl + return url.startsWith(nextcloudBaseUrl) + || (isRelativeUrl(url) && url.startsWith(getRootUrl())) } /** -- 2.39.5