@xmldom/xmldom 0.8.10 → 0.8.11

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/lib/dom.js +41 -2
  3. package/package.json +69 -69
package/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ 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.8.11](https://github.com/xmldom/xmldom/compare/0.8.10...0.8.11)
8
+
9
+ ### Fixed
10
+
11
+ - update `ownerDocument` when moving nodes between documents
12
+
13
+ Thank you, [@shunkica](https://github.com/shunkica), for your contributions
14
+
15
+
7
16
  ## [0.8.10](https://github.com/xmldom/xmldom/compare/0.8.9...0.8.10)
8
17
 
9
18
  ### Fixed
package/lib/dom.js CHANGED
@@ -980,6 +980,9 @@ function _insertBefore(parent, node, child, _inDocumentAssertion) {
980
980
  }
981
981
  do{
982
982
  newFirst.parentNode = parent;
983
+ // Update ownerDocument for each node being inserted
984
+ var targetDoc = parent.ownerDocument || parent;
985
+ _updateOwnerDocument(newFirst, targetDoc);
983
986
  }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
984
987
  _onUpdateChild(parent.ownerDocument||parent, parent);
985
988
  //console.log(parent.lastChild.nextSibling == null)
@@ -989,6 +992,37 @@ function _insertBefore(parent, node, child, _inDocumentAssertion) {
989
992
  return node;
990
993
  }
991
994
 
995
+ /**
996
+ * Recursively updates the ownerDocument property for a node and all its descendants
997
+ * @param {Node} node
998
+ * @param {Document} newOwnerDocument
999
+ * @private
1000
+ */
1001
+ function _updateOwnerDocument(node, newOwnerDocument) {
1002
+ if (node.ownerDocument === newOwnerDocument) {
1003
+ return;
1004
+ }
1005
+
1006
+ node.ownerDocument = newOwnerDocument;
1007
+
1008
+ // Update attributes if this is an element
1009
+ if (node.nodeType === ELEMENT_NODE && node.attributes) {
1010
+ for (var i = 0; i < node.attributes.length; i++) {
1011
+ var attr = node.attributes.item(i);
1012
+ if (attr) {
1013
+ attr.ownerDocument = newOwnerDocument;
1014
+ }
1015
+ }
1016
+ }
1017
+
1018
+ // Recursively update child nodes
1019
+ var child = node.firstChild;
1020
+ while (child) {
1021
+ _updateOwnerDocument(child, newOwnerDocument);
1022
+ child = child.nextSibling;
1023
+ }
1024
+ }
1025
+
992
1026
  /**
993
1027
  * Appends `newChild` to `parentNode`.
994
1028
  * If `newChild` is already connected to a `parentNode` it is first removed from it.
@@ -1014,6 +1048,11 @@ function _appendSingleChild (parentNode, newChild) {
1014
1048
  }
1015
1049
  parentNode.lastChild = newChild;
1016
1050
  _onUpdateChild(parentNode.ownerDocument, parentNode, newChild);
1051
+
1052
+ // Update ownerDocument for the new child and all its descendants
1053
+ var targetDoc = parentNode.ownerDocument || parentNode;
1054
+ _updateOwnerDocument(newChild, targetDoc);
1055
+
1017
1056
  return newChild;
1018
1057
  }
1019
1058
 
@@ -1042,7 +1081,7 @@ Document.prototype = {
1042
1081
  return newChild;
1043
1082
  }
1044
1083
  _insertBefore(this, newChild, refChild);
1045
- newChild.ownerDocument = this;
1084
+ _updateOwnerDocument(newChild, this);
1046
1085
  if (this.documentElement === null && newChild.nodeType === ELEMENT_NODE) {
1047
1086
  this.documentElement = newChild;
1048
1087
  }
@@ -1058,7 +1097,7 @@ Document.prototype = {
1058
1097
  replaceChild: function (newChild, oldChild) {
1059
1098
  //raises
1060
1099
  _insertBefore(this, newChild, oldChild, assertPreReplacementValidityInDocument);
1061
- newChild.ownerDocument = this;
1100
+ _updateOwnerDocument(newChild, this);
1062
1101
  if (oldChild) {
1063
1102
  this.removeChild(oldChild);
1064
1103
  }
package/package.json CHANGED
@@ -1,71 +1,71 @@
1
1
  {
2
- "name": "@xmldom/xmldom",
3
- "version": "0.8.10",
4
- "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
- "keywords": [
6
- "w3c",
7
- "dom",
8
- "xml",
9
- "parser",
10
- "javascript",
11
- "DOMParser",
12
- "XMLSerializer",
13
- "ponyfill"
14
- ],
15
- "homepage": "https://github.com/xmldom/xmldom",
16
- "repository": {
17
- "type": "git",
18
- "url": "git://github.com/xmldom/xmldom.git"
19
- },
20
- "main": "lib/index.js",
21
- "types": "index.d.ts",
22
- "files": [
23
- "CHANGELOG.md",
24
- "LICENSE",
25
- "readme.md",
26
- "SECURITY.md",
27
- "index.d.ts",
28
- "lib"
29
- ],
30
- "scripts": {
31
- "lint": "eslint lib test",
32
- "format": "prettier --write test",
33
- "changelog": "auto-changelog --unreleased-only",
34
- "start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
35
- "stryker": "stryker run",
36
- "stryker:dry-run": "stryker run -m '' --reporters progress",
37
- "test": "jest",
38
- "testrelease": "npm test && eslint lib",
39
- "version": "./changelog-has-version.sh",
40
- "release": "np --no-yarn --test-script testrelease --branch release-0.8.x patch"
41
- },
42
- "engines": {
43
- "node": ">=10.0.0"
44
- },
45
- "dependencies": {},
46
- "devDependencies": {
47
- "@stryker-mutator/core": "5.6.1",
48
- "auto-changelog": "2.4.0",
49
- "eslint": "8.25.0",
50
- "eslint-config-prettier": "8.5.0",
51
- "eslint-plugin-es5": "1.5.0",
52
- "eslint-plugin-prettier": "4.2.1",
53
- "get-stream": "6.0.1",
54
- "jest": "27.5.1",
55
- "nodemon": "2.0.20",
56
- "np": "7.6.2",
57
- "prettier": "2.7.1",
58
- "xmltest": "1.5.0",
59
- "yauzl": "2.10.0"
60
- },
61
- "bugs": {
62
- "url": "https://github.com/xmldom/xmldom/issues"
63
- },
64
- "license": "MIT",
65
- "auto-changelog": {
66
- "prepend": true,
67
- "remote": "upstream",
68
- "tagPrefix": "",
69
- "template": "./auto-changelog.hbs"
70
- }
2
+ "name": "@xmldom/xmldom",
3
+ "version": "0.8.11",
4
+ "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
+ "keywords": [
6
+ "w3c",
7
+ "dom",
8
+ "xml",
9
+ "parser",
10
+ "javascript",
11
+ "DOMParser",
12
+ "XMLSerializer",
13
+ "ponyfill"
14
+ ],
15
+ "homepage": "https://github.com/xmldom/xmldom",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git://github.com/xmldom/xmldom.git"
19
+ },
20
+ "main": "lib/index.js",
21
+ "types": "index.d.ts",
22
+ "files": [
23
+ "CHANGELOG.md",
24
+ "LICENSE",
25
+ "readme.md",
26
+ "SECURITY.md",
27
+ "index.d.ts",
28
+ "lib"
29
+ ],
30
+ "scripts": {
31
+ "lint": "eslint lib test",
32
+ "format": "prettier --write test",
33
+ "changelog": "auto-changelog --unreleased-only",
34
+ "start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
35
+ "stryker": "stryker run",
36
+ "stryker:dry-run": "stryker run -m '' --reporters progress",
37
+ "test": "jest",
38
+ "testrelease": "npm test && eslint lib",
39
+ "version": "./changelog-has-version.sh",
40
+ "release": "np --no-yarn --test-script testrelease --branch release-0.8.x patch"
41
+ },
42
+ "engines": {
43
+ "node": ">=10.0.0"
44
+ },
45
+ "dependencies": {},
46
+ "devDependencies": {
47
+ "@stryker-mutator/core": "5.6.1",
48
+ "auto-changelog": "2.4.0",
49
+ "eslint": "8.25.0",
50
+ "eslint-config-prettier": "8.5.0",
51
+ "eslint-plugin-es5": "1.5.0",
52
+ "eslint-plugin-prettier": "4.2.1",
53
+ "get-stream": "6.0.1",
54
+ "jest": "27.5.1",
55
+ "nodemon": "2.0.20",
56
+ "np": "9.2.0",
57
+ "prettier": "2.7.1",
58
+ "xmltest": "1.5.0",
59
+ "yauzl": "2.10.0"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/xmldom/xmldom/issues"
63
+ },
64
+ "license": "MIT",
65
+ "auto-changelog": {
66
+ "prepend": true,
67
+ "remote": "upstream",
68
+ "tagPrefix": "",
69
+ "template": "./auto-changelog.hbs"
70
+ }
71
71
  }