From ffd6c21ed4859b88ca0ced8ee9f789cada91e982 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 27 Sep 2022 13:54:54 -0600 Subject: [PATCH] Et2Select: Avoid errors if freeEntry has single quote --- .../etemplate/Et2Select/Et2WidgetWithSelectMixin.ts | 2 +- api/js/etemplate/Et2Select/SearchMixin.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts b/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts index 424e67aae4..9c5f15d7e6 100644 --- a/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts +++ b/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts @@ -156,7 +156,7 @@ export const Et2widgetWithSelectMixin = >(supe temp_target.querySelectorAll(":scope > *").forEach((item) => { // Avoid duplicate error - if(!this._optionTargetNode.querySelector("[value='" + item.value + "']")) + if(!this._optionTargetNode.querySelector("[value='" + item.value.replace(/'/g, '\\\'') + "']")) { this._optionTargetNode.appendChild(item); } diff --git a/api/js/etemplate/Et2Select/SearchMixin.ts b/api/js/etemplate/Et2Select/SearchMixin.ts index 3427a2368f..afbb289b0b 100644 --- a/api/js/etemplate/Et2Select/SearchMixin.ts +++ b/api/js/etemplate/Et2Select/SearchMixin.ts @@ -723,7 +723,7 @@ export const Et2WithSearchMixin = >(superclass { this.updateComplete.then(() => { - this.shadowRoot.querySelector("et2-tag[value='" + event.detail.item.value + "']")?.scrollIntoView(); + this.shadowRoot.querySelector("et2-tag[value='" + event.detail.item.value.replace(/'/g, "\\\'") + "']")?.scrollIntoView(); }); } } @@ -941,7 +941,7 @@ export const Et2WithSearchMixin = >(superclass // Remove remote options that aren't used let keepers = this._selected_remote.reduce((prev, current) => { - return ":not([value='" + current.value + "'])"; + return ":not([value='" + current.value.replace(/'/g, "\\\'") + "'])"; }, ""); target.querySelectorAll(".remote" + keepers).forEach(o => o.remove()); target.childNodes.forEach((n) => @@ -1073,7 +1073,7 @@ export const Et2WithSearchMixin = >(superclass temp_target.querySelectorAll(":scope > *").forEach((item) => { // Avoid duplicate error - if(!target.querySelector("[value='" + item.value + "']")) + if(!target.querySelector("[value='" + item.value.replace(/'/g, "\\\'") + "']")) { target.appendChild(item); } @@ -1120,7 +1120,7 @@ export const Et2WithSearchMixin = >(superclass return false; } // Make sure not to double-add - if(!this.querySelector("[value='" + text + "']") && !this.__select_options.find(o => o.value == text)) + if(!this.querySelector("[value='" + text.replace(/'/g, "\\\'") + "']") && !this.__select_options.find(o => o.value == text)) { this.__select_options.push({ value: text, @@ -1219,7 +1219,7 @@ export const Et2WithSearchMixin = >(superclass this.updateComplete.then(() => { - const item = this.querySelector("[value='" + value + "']"); + const item = this.querySelector("[value='" + value.replace(/'/g, "\\\'") + "']"); item.dispatchEvent(new CustomEvent("sl-select", {detail: {item}})); }) } @@ -1230,7 +1230,7 @@ export const Et2WithSearchMixin = >(superclass if(this.multiple) { this.value = this.value.filter(v => v !== original); - this.querySelector("[value='" + original + "']")?.remove(); + this.querySelector("[value='" + original.replace(/'/g, "\\\'") + "']")?.remove(); } else {