Skip to content

Commit

Permalink
fix: escape event target selector string
Browse files Browse the repository at this point in the history
  • Loading branch information
sergejcodes committed Aug 11, 2023
1 parent d078c07 commit a1dee96
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/minze/src/lib/minze-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export class MinzeElement extends HTMLElement {
type atEvent = [attribute: string, event: string, callback: string]

// get all @event attributes and remove duplicates
const atEventsRE = /@([a-zA-Z]+[\w\-_|:.]*)=["']?(\w+)["']?/gi
const atEventsRE = /@([\w\-_|:.]+)=["']?(\w+)["']?/gi
const atEvents: atEvent[] = [
...new Set(
[...template.matchAll(atEventsRE)].map((m) =>
Expand All @@ -765,7 +765,7 @@ export class MinzeElement extends HTMLElement {
if (eventListenersLength !== eventListenersLength + atEventsLength) {
atEvents.forEach(async ([selector, eventName, callbackName]) => {
const eventTuple: MinzeEvent = [
`[\\${selector}]`,
`[${selector}]`,
eventName,
this[callbackName]
]
Expand Down Expand Up @@ -797,7 +797,9 @@ export class MinzeElement extends HTMLElement {
} else if (eventTarget instanceof MinzeElement) {
elements = [this]
} else if (typeof eventTarget === 'string') {
elements = this.shadowRoot?.querySelectorAll(eventTarget)
const escapeTarget = (name: string) =>
name.replace(/(@|\||:|\.)/g, (_, $1) => `\\${$1}`)
elements = this.shadowRoot?.querySelectorAll(escapeTarget(eventTarget))
}

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

0 comments on commit a1dee96

Please sign in to comment.