From 0b76d64760c24b3f4110df5ef5299cbbeb960797 Mon Sep 17 00:00:00 2001 From: Andreas Kienast <a.fernandez@scripting-base.de> Date: Wed, 19 Jun 2024 15:10:56 +0200 Subject: [PATCH] [TASK] Deprecate `Utility.updateQueryStringParameter()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The method `Utility.updateQueryStringParameter()` from the module `@typo3/backend/utility.js` was introduced in TYPO3 v8 as a bugfix for highlighting in the old ExtJS-based page tree. With removal of ExtJS in TYPO3 v9, the method became unused since then. Since a safe removal of the method cannot be guaranteed as this point, it is therefore deprecated. Resolves: #104154 Related: #74180 Releases: main Change-Id: I90f0ff4c997ab31d690ff6f518f38ffb186058dd Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84786 Reviewed-by: Garvin Hicking <gh@faktor-e.de> Reviewed-by: Jasmina Ließmann <minapokhalo+typo3@gmail.com> Reviewed-by: Andreas Kienast <a.fernandez@scripting-base.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Andreas Kienast <a.fernandez@scripting-base.de> Tested-by: Garvin Hicking <gh@faktor-e.de> Tested-by: Jasmina Ließmann <minapokhalo+typo3@gmail.com> --- Build/Sources/TypeScript/backend/utility.ts | 3 ++ .../Resources/Public/JavaScript/utility.js | 2 +- ...ecateUtilityupdateQueryStringParameter.rst | 48 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/13.2/Deprecation-104154-DeprecateUtilityupdateQueryStringParameter.rst diff --git a/Build/Sources/TypeScript/backend/utility.ts b/Build/Sources/TypeScript/backend/utility.ts index bf2cb99f2d27..1b980590209e 100644 --- a/Build/Sources/TypeScript/backend/utility.ts +++ b/Build/Sources/TypeScript/backend/utility.ts @@ -75,8 +75,11 @@ class Utility { * @param {string} key * @param {string} value * @returns {string} + * @deprecated will be removed in TYPO3 v14 */ public static updateQueryStringParameter(url: string, key: string, value: string): string { + console.warn('Utility.updateQueryStringParameter() has been marked as deprecated and will be removed in TYPO3 v14.'); + const re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i'); const separator = url.includes('?') ? '&' : '?'; diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/utility.js b/typo3/sysext/backend/Resources/Public/JavaScript/utility.js index 8f9c53d96588..c89806bc7a03 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/utility.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/utility.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -class Utility{static trimExplode(t,e){return e.split(t).map((t=>t.trim())).filter((t=>""!==t))}static trimItems(t){return t.map((t=>t instanceof String?t.trim():t))}static intExplode(t,e,r=!1){return e.split(t).map((t=>parseInt(t,10))).filter((t=>!isNaN(t)||r&&0===t))}static isNumber(t){return!isNaN(parseFloat(t.toString()))&&isFinite(t)}static updateQueryStringParameter(t,e,r){const i=new RegExp("([?&])"+e+"=.*?(&|$)","i"),a=t.includes("?")?"&":"?";return t.match(i)?t.replace(i,"$1"+e+"="+r+"$2"):t+a+e+"="+r}static convertFormToObject(t){const e={};return t.querySelectorAll("input, select, textarea").forEach((t=>{const r=t.name,i=t.value;if(r)if("input"===t.tagName.toLowerCase()&&"checkbox"==t.type){const a=t;void 0===e[r]&&(e[r]=[]),a.checked&&e[r].push(i)}else e[r]=i})),e}static mergeDeep(...t){const e=t=>t&&"object"==typeof t;return t.reduce(((t,r)=>(Object.keys(r).forEach((i=>{const a=t[i],n=r[i];Array.isArray(a)&&Array.isArray(n)?t[i]=a.concat(...n):e(a)&&e(n)?t[i]=Utility.mergeDeep(a,n):t[i]=n})),t)),{})}static urlsPointToSameServerSideResource(t,e){if(!t||!e)return!1;const r=window.location.origin;try{const i=new URL(t,Utility.isValidUrl(t)?void 0:r),a=new URL(e,Utility.isValidUrl(e)?void 0:r),n=i.origin+i.pathname+i.search;return n===a.origin+a.pathname+a.search}catch(t){return!1}}static isValidUrl(t){try{return new URL(t),!0}catch(t){return!1}}}export default Utility; \ No newline at end of file +class Utility{static trimExplode(t,e){return e.split(t).map((t=>t.trim())).filter((t=>""!==t))}static trimItems(t){return t.map((t=>t instanceof String?t.trim():t))}static intExplode(t,e,r=!1){return e.split(t).map((t=>parseInt(t,10))).filter((t=>!isNaN(t)||r&&0===t))}static isNumber(t){return!isNaN(parseFloat(t.toString()))&&isFinite(t)}static updateQueryStringParameter(t,e,r){console.warn("Utility.updateQueryStringParameter() has been marked as deprecated and will be removed in TYPO3 v14.");const i=new RegExp("([?&])"+e+"=.*?(&|$)","i"),a=t.includes("?")?"&":"?";return t.match(i)?t.replace(i,"$1"+e+"="+r+"$2"):t+a+e+"="+r}static convertFormToObject(t){const e={};return t.querySelectorAll("input, select, textarea").forEach((t=>{const r=t.name,i=t.value;if(r)if("input"===t.tagName.toLowerCase()&&"checkbox"==t.type){const a=t;void 0===e[r]&&(e[r]=[]),a.checked&&e[r].push(i)}else e[r]=i})),e}static mergeDeep(...t){const e=t=>t&&"object"==typeof t;return t.reduce(((t,r)=>(Object.keys(r).forEach((i=>{const a=t[i],n=r[i];Array.isArray(a)&&Array.isArray(n)?t[i]=a.concat(...n):e(a)&&e(n)?t[i]=Utility.mergeDeep(a,n):t[i]=n})),t)),{})}static urlsPointToSameServerSideResource(t,e){if(!t||!e)return!1;const r=window.location.origin;try{const i=new URL(t,Utility.isValidUrl(t)?void 0:r),a=new URL(e,Utility.isValidUrl(e)?void 0:r),n=i.origin+i.pathname+i.search;return n===a.origin+a.pathname+a.search}catch(t){return!1}}static isValidUrl(t){try{return new URL(t),!0}catch(t){return!1}}}export default Utility; \ No newline at end of file diff --git a/typo3/sysext/core/Documentation/Changelog/13.2/Deprecation-104154-DeprecateUtilityupdateQueryStringParameter.rst b/typo3/sysext/core/Documentation/Changelog/13.2/Deprecation-104154-DeprecateUtilityupdateQueryStringParameter.rst new file mode 100644 index 000000000000..adc137ee1ca8 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/13.2/Deprecation-104154-DeprecateUtilityupdateQueryStringParameter.rst @@ -0,0 +1,48 @@ +.. include:: /Includes.rst.txt + +.. _deprecation-104154-1718802119: + +===================================================================== +Deprecation: #104154 - Deprecate Utility.updateQueryStringParameter() +===================================================================== + +See :issue:`104154` + +Description +=========== + +The method :js:`Utility.updateQueryStringParameter()` from the module +:js:`@typo3/backend/utility.js` was introduced in TYPO3 v8 as a bugfix for +highlighting in the old ExtJS-based page tree. With removal of ExtJS in TYPO3 v9, +the method became unused since then. + +Since a safe removal of the method cannot be guaranteed as this point, it is +therefore deprecated. + + +Impact +====== + +Calling :js:`Utility.updateQueryStringParameter()` will result in a JavaScript +warning. + + +Affected installations +====================== + +All 3rd party extensions using the deprecated method are affected. + + +Migration +========= + +Nowadays, JavaScript supports the :js:`URL` and its related :js:`URLSearchParams` +object that can be used to achieve the same result: + +.. code-block:: javascript + + const url = new URL('http://localhost?baz=baz'); + url.searchParams.set('baz', 'bencer'); + const urlString = url.toString(); // http://localhost?baz=bencer + +.. index:: JavaScript, NotScanned, ext:backend -- GitLab