From b44b0d5297320dac23199446001b6889993d8b68 Mon Sep 17 00:00:00 2001 From: tischsoic Date: Thu, 15 Jan 2026 10:41:27 +0100 Subject: [PATCH 1/3] IBX-11093: Add TS dom.helper and text.helper --- .../public/js/scripts/helpers/dom.helper.js | 21 ------------ .../public/js/scripts/helpers/dom.helper.ts | 33 +++++++++++++++++++ .../public/js/scripts/helpers/text.helper.js | 24 -------------- .../public/js/scripts/helpers/text.helper.ts | 19 +++++++++++ 4 files changed, 52 insertions(+), 45 deletions(-) delete mode 100644 src/bundle/Resources/public/js/scripts/helpers/dom.helper.js create mode 100644 src/bundle/Resources/public/js/scripts/helpers/dom.helper.ts delete mode 100644 src/bundle/Resources/public/js/scripts/helpers/text.helper.js create mode 100644 src/bundle/Resources/public/js/scripts/helpers/text.helper.ts diff --git a/src/bundle/Resources/public/js/scripts/helpers/dom.helper.js b/src/bundle/Resources/public/js/scripts/helpers/dom.helper.js deleted file mode 100644 index bd6c35c43f..0000000000 --- a/src/bundle/Resources/public/js/scripts/helpers/dom.helper.js +++ /dev/null @@ -1,21 +0,0 @@ -import { escapeHTML } from './text.helper'; - -const safelySetInnerHTML = (node, text) => { - node.innerHTML = escapeHTML(text); -}; - -const dangerouslySetInnerHTML = (node, text) => { - node.innerHTML = text; -}; - -const dangerouslyInsertAdjacentHTML = (node, position, text) => { - const escapedText = text; - - node.insertAdjacentHTML(position, escapedText); -}; - -const dangerouslyAppend = (node, nodeOrText) => { - node.append(nodeOrText); -}; - -export { safelySetInnerHTML, dangerouslySetInnerHTML, dangerouslyInsertAdjacentHTML, dangerouslyAppend }; diff --git a/src/bundle/Resources/public/js/scripts/helpers/dom.helper.ts b/src/bundle/Resources/public/js/scripts/helpers/dom.helper.ts new file mode 100644 index 0000000000..4bc81bf444 --- /dev/null +++ b/src/bundle/Resources/public/js/scripts/helpers/dom.helper.ts @@ -0,0 +1,33 @@ +import { escapeHTML } from './text.helper'; + +const safelySetInnerHTML = (node: HTMLElement, text: string): void => { + // eslint-disable-next-line no-param-reassign + node.innerHTML = escapeHTML(text); +}; + +const dangerouslySetInnerHTML = (node: HTMLElement, text: string): void => { + // eslint-disable-next-line no-param-reassign + node.innerHTML = text; +}; + +const dangerouslyInsertAdjacentHTML = (node: HTMLElement, position: InsertPosition, text: string): void => { + const escapedText = text; + + node.insertAdjacentHTML(position, escapedText); +}; + +const dangerouslyAppend = (node: HTMLElement, nodeOrText: Node | string): void => { + node.append(nodeOrText); +}; + +const notNullQuerySelector = function (node: HTMLElement | Document, selector: string): T { + const selectedNode = node.querySelector(selector); + + if (!selectedNode) { + throw new Error(`Element for selector '${selector}' not found!`); + } + + return selectedNode; +}; + +export { safelySetInnerHTML, dangerouslySetInnerHTML, dangerouslyInsertAdjacentHTML, dangerouslyAppend, notNullQuerySelector }; diff --git a/src/bundle/Resources/public/js/scripts/helpers/text.helper.js b/src/bundle/Resources/public/js/scripts/helpers/text.helper.js deleted file mode 100644 index ac5f88cc3c..0000000000 --- a/src/bundle/Resources/public/js/scripts/helpers/text.helper.js +++ /dev/null @@ -1,24 +0,0 @@ -const { document: doc } = window; - -const escapeHTML = (string) => { - const stringTempNode = doc.createElement('div'); - - stringTempNode.appendChild(doc.createTextNode(string)); - - return stringTempNode.innerHTML; -}; - -const escapeHTMLAttribute = (string) => { - if (string === null) { - return ''; - } - - return String(string) - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); -}; - -export { escapeHTML, escapeHTMLAttribute }; diff --git a/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts b/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts new file mode 100644 index 0000000000..1df7150fdf --- /dev/null +++ b/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts @@ -0,0 +1,19 @@ +const { document: doc } = window; + +const escapeHTML = (str: string): string => { + const stringTempNode = doc.createElement('div'); + + stringTempNode.appendChild(doc.createTextNode(str)); + + return stringTempNode.innerHTML; +}; + +const escapeHTMLAttribute = (str: string | null): string => { + if (str === null) { + return ''; + } + + return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); +}; + +export { escapeHTML, escapeHTMLAttribute }; From 4b32669ac90912121fdc1b0ca54fc38f7512cf07 Mon Sep 17 00:00:00 2001 From: tischsoic Date: Fri, 13 Feb 2026 10:28:56 +0100 Subject: [PATCH 2/3] fix text helper --- .../Resources/public/js/scripts/helpers/text.helper.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts b/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts index 1df7150fdf..7a8bd2d8d9 100644 --- a/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts +++ b/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts @@ -8,12 +8,12 @@ const escapeHTML = (str: string): string => { return stringTempNode.innerHTML; }; -const escapeHTMLAttribute = (str: string | null): string => { - if (str === null) { +const escapeHTMLAttribute = (str: unknown): string => { + if (str === null || str === undefined) { return ''; } - return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); + return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); }; export { escapeHTML, escapeHTMLAttribute }; From 1e41eb58dacf849f3fa6c9e122848062c8a27a17 Mon Sep 17 00:00:00 2001 From: tischsoic Date: Fri, 13 Feb 2026 10:35:45 +0100 Subject: [PATCH 3/3] eslint fix --- src/bundle/Resources/public/js/scripts/helpers/text.helper.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts b/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts index 7a8bd2d8d9..994c33b193 100644 --- a/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts +++ b/src/bundle/Resources/public/js/scripts/helpers/text.helper.ts @@ -13,6 +13,7 @@ const escapeHTMLAttribute = (str: unknown): string => { return ''; } + // eslint-disable-next-line @typescript-eslint/no-base-to-string return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); };