@xmldom/xmldom 0.9.0-beta.4 → 0.9.0-beta.5

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/CHANGELOG.md CHANGED
@@ -4,6 +4,33 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.9.0-beta.5](https://github.com/xmldom/xmldom/compare/0.9.0-beta.4...0.9.0-beta.5)
8
+
9
+ ### Merged
10
+
11
+ - fix: Restore ES5 compatibility [`#452`](https://github.com/xmldom/xmldom/pull/452) / [`#453`](https://github.com/xmldom/xmldom/issues/453)
12
+
13
+ Thank you, [@fengxinming](https://github.com/fengxinming), for your contributions
14
+
15
+
16
+ ## [0.8.5](https://github.com/xmldom/xmldom/compare/0.8.4...0.8.5)
17
+
18
+ ### Merged
19
+
20
+ - fix: Restore ES5 compatibility [`#452`](https://github.com/xmldom/xmldom/pull/452) / [`#453`](https://github.com/xmldom/xmldom/issues/453)
21
+
22
+ Thank you, [@fengxinming](https://github.com/fengxinming), for your contributions
23
+
24
+
25
+ ## [0.7.8](https://github.com/xmldom/xmldom/compare/0.7.7...0.7.8)
26
+
27
+ ### Merged
28
+
29
+ - fix: Restore ES5 compatibility [`#452`](https://github.com/xmldom/xmldom/pull/452) / [`#453`](https://github.com/xmldom/xmldom/issues/453)
30
+
31
+ Thank you, [@fengxinming](https://github.com/fengxinming), for your contributions
32
+
33
+
7
34
  ## [0.9.0-beta.4](https://github.com/xmldom/xmldom/compare/0.9.0-beta.3...0.9.0-beta.4)
8
35
 
9
36
  ### Fixed
@@ -22,6 +49,33 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
22
49
 
23
50
  Thank you, [@XhmikosR](https://github.com/XhmikosR), [@awwright](https://github.com/awwright), [@frumioj](https://github.com/frumioj), [@cjbarth](https://github.com/cjbarth), [@markgollnick](https://github.com/markgollnick) for your contributions
24
51
 
52
+
53
+ ## [0.8.4](https://github.com/xmldom/xmldom/compare/0.8.3...0.8.4)
54
+
55
+ ### Fixed
56
+
57
+ - Security: Prevent inserting DOM nodes when they are not well-formed [`CVE-2022-39353`](https://github.com/xmldom/xmldom/security/advisories/GHSA-crh6-fp67-6883)
58
+ In case such a DOM would be created, the part that is not well-formed will be transformed into text nodes, in which xml specific characters like `<` and `>` are encoded accordingly.
59
+ In the upcoming version 0.9.0 those text nodes will no longer be added and an error will be thrown instead.
60
+ This change can break your code, if you relied on this behavior, e.g. multiple root elements in the past. We consider it more important to align with the specs that we want to be aligned with, considering the potential security issues that might derive from people not being aware of the difference in behavior.
61
+ Related Spec: <https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity>
62
+
63
+ Thank you, [@frumioj](https://github.com/frumioj), [@cjbarth](https://github.com/cjbarth), [@markgollnick](https://github.com/markgollnick) for your contributions
64
+
65
+
66
+ ## [0.7.7](https://github.com/xmldom/xmldom/compare/0.7.6...0.7.7)
67
+
68
+ ### Fixed
69
+
70
+ - Security: Prevent inserting DOM nodes when they are not well-formed [`CVE-2022-39353`](https://github.com/xmldom/xmldom/security/advisories/GHSA-crh6-fp67-6883)
71
+ In case such a DOM would be created, the part that is not well-formed will be transformed into text nodes, in which xml specific characters like `<` and `>` are encoded accordingly.
72
+ In the upcoming version 0.9.0 those text nodes will no longer be added and an error will be thrown instead.
73
+ This change can break your code, if you relied on this behavior, e.g. multiple root elements in the past. We consider it more important to align with the specs that we want to be aligned with, considering the potential security issues that might derive from people not being aware of the difference in behavior.
74
+ Related Spec: <https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity>
75
+
76
+ Thank you, [@frumioj](https://github.com/frumioj), [@cjbarth](https://github.com/cjbarth), [@markgollnick](https://github.com/markgollnick) for your contributions
77
+
78
+
25
79
  ## [0.9.0-beta.3](https://github.com/xmldom/xmldom/compare/0.9.0-beta.2...0.9.0-beta.3)
26
80
 
27
81
  ### Fixed
@@ -1,5 +1,37 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * Ponyfill for `Array.prototype.find` which is only available in ES6 runtimes.
5
+ *
6
+ * Works with anything that has a `length` property and index access properties, including NodeList.
7
+ *
8
+ * @template {unknown} T
9
+ * @param {Array<T> | ({length:number, [number]: T})} list
10
+ * @param {function (item: T, index: number, list:Array<T> | ({length:number, [number]: T})):boolean} predicate
11
+ * @param {Partial<Pick<ArrayConstructor['prototype'], 'find'>>?} ac `Array.prototype` by default,
12
+ * allows injecting a custom implementation in tests
13
+ * @returns {T | undefined}
14
+ *
15
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
16
+ * @see https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.find
17
+ */
18
+ function find(list, predicate, ac) {
19
+ if (ac === undefined) {
20
+ ac = Array.prototype;
21
+ }
22
+ if (list && typeof ac.find === 'function') {
23
+ return ac.find.call(list, predicate);
24
+ }
25
+ for (var i = 0; i < list.length; i++) {
26
+ if (Object.prototype.hasOwnProperty.call(list, i)) {
27
+ var item = list[i];
28
+ if (predicate.call(undefined, item, i, list)) {
29
+ return item;
30
+ }
31
+ }
32
+ }
33
+ }
34
+
3
35
  /**
4
36
  * "Shallow freezes" an object to render it immutable.
5
37
  * Uses `Object.freeze` if available,
@@ -330,6 +362,7 @@ var NAMESPACE = freeze({
330
362
  });
331
363
 
332
364
  exports.assign = assign;
365
+ exports.find = find;
333
366
  exports.freeze = freeze;
334
367
  exports.HTML_BOOLEAN_ATTRIBUTES = HTML_BOOLEAN_ATTRIBUTES;
335
368
  exports.HTML_RAW_TEXT_ELEMENTS = HTML_RAW_TEXT_ELEMENTS;
package/lib/dom.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var conventions = require('./conventions');
4
+ var find = conventions.find;
4
5
  var isHTMLRawTextElement = conventions.isHTMLRawTextElement;
5
6
  var isHTMLVoidElement = conventions.isHTMLVoidElement;
6
7
  var MIME_TYPE = conventions.MIME_TYPE;
@@ -180,14 +181,6 @@ NodeList.prototype = {
180
181
  }
181
182
  return buf.join('');
182
183
  },
183
- /**
184
- * @private
185
- * @param {function (Node):boolean} predicate
186
- * @returns {Node | undefined}
187
- */
188
- find: function (predicate) {
189
- return Array.prototype.find.call(this, predicate);
190
- },
191
184
  /**
192
185
  * @private
193
186
  * @param {function (Node):boolean} predicate
@@ -832,10 +825,10 @@ function isTextNode(node) {
832
825
  */
833
826
  function isElementInsertionPossible(doc, child) {
834
827
  var parentChildNodes = doc.childNodes || [];
835
- if (parentChildNodes.find(isElementNode) || isDocTypeNode(child)) {
828
+ if (find(parentChildNodes, isElementNode) || isDocTypeNode(child)) {
836
829
  return false;
837
830
  }
838
- var docTypeNode = parentChildNodes.find(isDocTypeNode);
831
+ var docTypeNode = find(parentChildNodes, isDocTypeNode);
839
832
  return !(child && docTypeNode && parentChildNodes.indexOf(docTypeNode) > parentChildNodes.indexOf(child));
840
833
  }
841
834
  /**
@@ -870,8 +863,8 @@ function _insertBefore(parent, node, child) {
870
863
  var nodeChildNodes = node.childNodes || [];
871
864
  if (parent.nodeType === Node.DOCUMENT_NODE) {
872
865
  if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
873
- let nodeChildElements = nodeChildNodes.filter(isElementNode);
874
- if (nodeChildElements.length > 1 || nodeChildNodes.find(isTextNode)) {
866
+ var nodeChildElements = nodeChildNodes.filter(isElementNode);
867
+ if (nodeChildElements.length > 1 || find(nodeChildNodes, isTextNode)) {
875
868
  throw new DOMException(HIERARCHY_REQUEST_ERR, 'More than one element or text in fragment');
876
869
  }
877
870
  if (nodeChildElements.length === 1 && !isElementInsertionPossible(parent, child)) {
@@ -879,15 +872,15 @@ function _insertBefore(parent, node, child) {
879
872
  }
880
873
  }
881
874
  if (isElementNode(node)) {
882
- if (parentChildNodes.find(isElementNode) || !isElementInsertionPossible(parent, child)) {
875
+ if (find(parentChildNodes, isElementNode) || !isElementInsertionPossible(parent, child)) {
883
876
  throw new DOMException(HIERARCHY_REQUEST_ERR, 'Only one element can be added and only after doctype');
884
877
  }
885
878
  }
886
879
  if (isDocTypeNode(node)) {
887
- if (parentChildNodes.find(isDocTypeNode)) {
880
+ if (find(parentChildNodes, isDocTypeNode)) {
888
881
  throw new DOMException(HIERARCHY_REQUEST_ERR, 'Only one doctype is allowed');
889
882
  }
890
- let parentElementChild = parentChildNodes.find(isElementNode);
883
+ var parentElementChild = find(parentChildNodes, isElementNode);
891
884
  if (child && parentChildNodes.indexOf(parentElementChild) < parentChildNodes.indexOf(child)) {
892
885
  throw new DOMException(HIERARCHY_REQUEST_ERR, 'Doctype can only be inserted before an element');
893
886
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmldom/xmldom",
3
- "version": "0.9.0-beta.4",
3
+ "version": "0.9.0-beta.5",
4
4
  "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
5
  "keywords": [
6
6
  "w3c",
@@ -35,8 +35,9 @@
35
35
  "stryker": "stryker run",
36
36
  "stryker:dry-run": "stryker run -m '' --reporters progress",
37
37
  "test": "jest",
38
+ "testrelease": "npm test && npm run lint",
38
39
  "version": "./changelog-has-version.sh",
39
- "release": "np --no-yarn"
40
+ "release": "np --no-yarn --test-script testrelease"
40
41
  },
41
42
  "engines": {
42
43
  "node": ">=10.0.0"