Skip to content

Commit

Permalink
fix: escape only at-event selectors automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
sergejcodes committed Aug 11, 2023
1 parent 470f6e6 commit 3113402
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/minze/src/lib/minze-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,9 @@ export class MinzeElement extends HTMLElement {
].map((e) => JSON.parse(e))

if (atEvents.length) {
const escapeSelector = (name: string) =>
name.replace(/(@|\||:|\.)/g, (_, $1) => `\\${$1}`)

this.eventListeners ??= []
const eventListenersLength = this.eventListeners.length
const atEventsLength = atEvents.length
Expand All @@ -765,7 +768,7 @@ export class MinzeElement extends HTMLElement {
if (eventListenersLength !== eventListenersLength + atEventsLength) {
atEvents.forEach(async ([selector, eventName, callbackName]) => {
const eventTuple: MinzeEvent = [
`[${selector}]`,
`[${escapeSelector(selector)}]`,
eventName,
this[callbackName]
]
Expand Down Expand Up @@ -797,9 +800,7 @@ export class MinzeElement extends HTMLElement {
} else if (eventTarget instanceof MinzeElement) {
elements = [this]
} else if (typeof eventTarget === 'string') {
const escapeTarget = (name: string) =>
name.replace(/(@|\||:|\.)/g, (_, $1) => `\\${$1}`)
elements = this.shadowRoot?.querySelectorAll(escapeTarget(eventTarget))
elements = this.shadowRoot?.querySelectorAll(eventTarget)
}

elements?.forEach((element: Node | MinzeElement | typeof window) => {
Expand Down

0 comments on commit 3113402

Please sign in to comment.