From 9a41fb0a27e42d95be2eaf61612ed2824fbd0780 Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Wed, 13 Dec 2023 19:10:03 +0100 Subject: [PATCH] [BUGFIX] Consider empty or invalid password policy reference In case `$GLOBALS['TYPO3_CONF_VARS']['BE']['passwordPolicy']` is disabled or set to a preset that actually does not exist, the backend editing view should not issue JavaScript errors on the missing `#password-policy-info` element. Resolves: #102668 Releases: main, 12.4 Change-Id: Iafb418254f73f379364b04c5d45d33111bef7d13 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82123 Reviewed-by: Oliver Bartsch Tested-by: core-ci Tested-by: Oliver Bartsch --- .../backend/form-engine/element/password-element.ts | 4 ++-- .../Public/JavaScript/form-engine/element/password-element.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Build/Sources/TypeScript/backend/form-engine/element/password-element.ts b/Build/Sources/TypeScript/backend/form-engine/element/password-element.ts index ab9fdb3c681c..089ea5ab3cbd 100644 --- a/Build/Sources/TypeScript/backend/form-engine/element/password-element.ts +++ b/Build/Sources/TypeScript/backend/form-engine/element/password-element.ts @@ -28,7 +28,7 @@ import { selector } from '@typo3/core/literals'; */ class PasswordElement extends HTMLElement { private element: HTMLInputElement = null; - private passwordPolicyInfo: HTMLElement = null; + private passwordPolicyInfo: HTMLElement|null = null; private passwordPolicySet: boolean = false; public connectedCallback(): void { @@ -49,7 +49,7 @@ class PasswordElement extends HTMLElement { } private registerEventHandler(): void { - if (this.passwordPolicySet) { + if (this.passwordPolicySet && this.passwordPolicyInfo !== null) { this.element.addEventListener('focusin', (): void => { this.passwordPolicyInfo.classList.remove('hidden'); }); diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/form-engine/element/password-element.js b/typo3/sysext/backend/Resources/Public/JavaScript/form-engine/element/password-element.js index 9b4a853958a6..2f25fbcc8d07 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/form-engine/element/password-element.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/form-engine/element/password-element.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -import{selector}from"@typo3/core/literals.js";class PasswordElement extends HTMLElement{constructor(){super(...arguments),this.element=null,this.passwordPolicyInfo=null,this.passwordPolicySet=!1}connectedCallback(){const e=this.getAttribute("recordFieldId");null!==e&&(this.element=this.querySelector(selector`#${e}`),this.element&&(this.passwordPolicyInfo=this.querySelector(selector`#password-policy-info-${this.element.id}`),this.passwordPolicySet=""!==(this.getAttribute("passwordPolicy")||""),this.registerEventHandler()))}registerEventHandler(){this.passwordPolicySet&&(this.element.addEventListener("focusin",(()=>{this.passwordPolicyInfo.classList.remove("hidden")})),this.element.addEventListener("focusout",(()=>{this.passwordPolicyInfo.classList.add("hidden")})))}}window.customElements.define("typo3-formengine-element-password",PasswordElement); \ No newline at end of file +import{selector}from"@typo3/core/literals.js";class PasswordElement extends HTMLElement{constructor(){super(...arguments),this.element=null,this.passwordPolicyInfo=null,this.passwordPolicySet=!1}connectedCallback(){const e=this.getAttribute("recordFieldId");null!==e&&(this.element=this.querySelector(selector`#${e}`),this.element&&(this.passwordPolicyInfo=this.querySelector(selector`#password-policy-info-${this.element.id}`),this.passwordPolicySet=""!==(this.getAttribute("passwordPolicy")||""),this.registerEventHandler()))}registerEventHandler(){this.passwordPolicySet&&null!==this.passwordPolicyInfo&&(this.element.addEventListener("focusin",(()=>{this.passwordPolicyInfo.classList.remove("hidden")})),this.element.addEventListener("focusout",(()=>{this.passwordPolicyInfo.classList.add("hidden")})))}}window.customElements.define("typo3-formengine-element-password",PasswordElement); \ No newline at end of file