]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix adding x-requested-with header for relative URLs when the base NC URL is empty
authorJulien Veyssier <julien-nc@posteo.net>
Tue, 21 Nov 2023 09:55:37 +0000 (10:55 +0100)
committerFerdinand Thiessen <opensource@fthiessen.de>
Fri, 24 Nov 2023 10:33:08 +0000 (11:33 +0100)
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
core/src/utils/xhr-request.js

index 66f994246e0bcf1c4efbf76851ac8f874e298df7..ff8b7641b07d895f1402661bdaf92b5bb58c32de 100644 (file)
 
 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()))
 }
 
 /**