@webtides/element-js 1.2.0 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtides/element-js",
3
- "version": "1.2.0",
3
+ "version": "1.2.3",
4
4
  "module": "index.js",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -587,8 +587,10 @@ class BaseElement extends HTMLElement {
587
587
  */
588
588
  removeEvents() {
589
589
  this._registeredEvents.forEach(({ eventTarget, eventName, callback }) => {
590
- if (eventTarget === window || eventTarget === document || this.getRoot().contains(eventTarget)) {
590
+ try {
591
591
  eventTarget.removeEventListener(eventName, callback);
592
+ } catch (e) {
593
+ console.error('Unable to remove event listener', e);
592
594
  }
593
595
  });
594
596
  this._registeredEvents = [];
@@ -21,6 +21,9 @@ export const insertNodesBetweenComments = (commentNode, nodes) => {
21
21
  export const replaceNodesBetweenComments = (commentNode, nodes) => {
22
22
  removeNodesBetweenComments(commentNode);
23
23
  for (const node of nodes) {
24
+ if (!commentNode.parentNode) {
25
+ console.error(`--- no parent comment ---`);
26
+ }
24
27
  commentNode.parentNode.insertBefore(node, commentNode);
25
28
  }
26
29
  };
@@ -6,7 +6,7 @@ const voidElements = /^(?:area|base|br|col|embed|hr|img|input|link|meta|source|t
6
6
  const rawTextElements = /<(script|style|textarea|title)([^>]*)>(.*?)<\/\1>/i;
7
7
  const elements = /<([a-z]+[a-z0-9:._-]*)([^>]*?)(\/?)>/g;
8
8
  // TODO: v this will not match any values with escaped quotes like onClick='console.log("\'test")'
9
- const attributes = /([^\s]*)=((?:")[^"]*(?:")|(?:')[^']*(?:')|[^\s\/>]*)|([^\s\/>]*)/g;
9
+ const attributes = /([^\s=]*)=((?:")[^"]*(?:")|(?:')[^']*(?:')|[^\s\/>]*)|([^\s\/>]*)/g;
10
10
  const partPositions = /[\x01\x02]/g;
11
11
  const ssrPlaceholder = /{{dom-part\?(.*?)}}/g;
12
12
  // \x01 Node.ELEMENT_NODE
@@ -125,16 +125,20 @@ export function camelToDash(string) {
125
125
  }
126
126
 
127
127
  /**
128
- * Decodes an attribute according to {@link https://html.spec.whatwg.org/multipage/syntax.html#attributes-2}
128
+ * Decodes an attribute according to {@link https://html.spec.whatwg.org/multipage/syntax.html#attributes-2} & {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}
129
129
  * @param {string} attribute
130
130
  * @returns {string}
131
131
  */
132
132
  export function decodeAttribute(attribute) {
133
- return `${attribute}`.replace(/&quot;/g, '"').replace(/&amp;/g, '&');
133
+ return `${attribute}`
134
+ .replace(/&lt;/g, '<')
135
+ .replace(/&gt;/g, '>')
136
+ .replace(/&quot;/g, '"')
137
+ .replace(/&amp;/g, '&');
134
138
  }
135
139
 
136
140
  /**
137
- * Encodes an attribute according to {@link https://html.spec.whatwg.org/multipage/syntax.html#attributes-2}
141
+ * Encodes an attribute according to {@link https://html.spec.whatwg.org/multipage/syntax.html#attributes-2} & {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}
138
142
  * @param {string} attribute
139
143
  * @returns {string}
140
144
  */
@@ -142,6 +146,8 @@ export function encodeAttribute(attribute) {
142
146
  return `${attribute}`
143
147
  .replace(/&/g, '&amp;')
144
148
  .replace(/"/g, '&quot;')
149
+ .replace(/</g, '&lt;')
150
+ .replace(/>/g, '&gt;')
145
151
  .replace(/\r\n/g, '\n')
146
152
  .replace(/[\r\n]/g, '\n');
147
153
  }