@xmldom/xmldom 0.7.4 → 0.7.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,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.7.5
8
+
9
+ [Commits](https://github.com/xmldom/xmldom/compare/0.7.4...0.7.5)
10
+
11
+ ### Fixes:
12
+
13
+ - Preserve default namespace when serializing [`#319`](https://github.com/xmldom/xmldom/issues/319) / [`#321`](https://github.com/xmldom/xmldom/pull/321)
14
+ Thank you [@lupestro](https://github.com/lupestro)
15
+
7
16
  ## 0.7.4
8
17
 
9
18
  [Commits](https://github.com/xmldom/xmldom/compare/0.7.3...0.7.4)
package/lib/dom.js CHANGED
@@ -488,6 +488,20 @@ Node.prototype = {
488
488
  hasAttributes:function(){
489
489
  return this.attributes.length>0;
490
490
  },
491
+ /**
492
+ * Look up the prefix associated to the given namespace URI, starting from this node.
493
+ * **The default namespace declarations are ignored by this method.**
494
+ * See Namespace Prefix Lookup for details on the algorithm used by this method.
495
+ *
496
+ * _Note: The implementation seems to be incomplete when compared to the algorithm described in the specs._
497
+ *
498
+ * @param {string | null} namespaceURI
499
+ * @returns {string | null}
500
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespacePrefix
501
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#lookupNamespacePrefixAlgo
502
+ * @see https://dom.spec.whatwg.org/#dom-node-lookupprefix
503
+ * @see https://github.com/xmldom/xmldom/issues/322
504
+ */
491
505
  lookupPrefix:function(namespaceURI){
492
506
  var el = this;
493
507
  while(el){
@@ -1175,12 +1189,23 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
1175
1189
  var prefixedNodeName = nodeName
1176
1190
  if (!isHTML && !node.prefix && node.namespaceURI) {
1177
1191
  var defaultNS
1192
+ // lookup current default ns from `xmlns` attribute
1178
1193
  for (var ai = 0; ai < attrs.length; ai++) {
1179
1194
  if (attrs.item(ai).name === 'xmlns') {
1180
1195
  defaultNS = attrs.item(ai).value
1181
1196
  break
1182
1197
  }
1183
1198
  }
1199
+ if (!defaultNS) {
1200
+ // lookup current default ns in visibleNamespaces
1201
+ for (var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--) {
1202
+ var namespace = visibleNamespaces[nsi]
1203
+ if (namespace.prefix === '' && namespace.namespace === node.namespaceURI) {
1204
+ defaultNS = namespace.namespace
1205
+ break
1206
+ }
1207
+ }
1208
+ }
1184
1209
  if (defaultNS !== node.namespaceURI) {
1185
1210
  for (var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--) {
1186
1211
  var namespace = visibleNamespaces[nsi]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmldom/xmldom",
3
- "version": "0.7.4",
3
+ "version": "0.7.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",