Skip to content

Commit 76a43f5

Browse files
committed
Only use the CanonicalizationMethod/InclusiveNameSpace if one was not
explicitly provided
1 parent 08e4eff commit 76a43f5

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

lib/exclusive-canonicalization.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -202,32 +202,33 @@ ExclusiveCanonicalization.prototype.process = function(node, options) {
202202
var ancestorNamespaces = options.ancestorNamespaces || [];
203203

204204
/**
205-
* Get the InclusiveNamespaces PrefixList
206-
*/
207-
var inclusiveNamespacesPrefixList = options.inclusiveNamespacesPrefixList || [];
208-
var CanonicalizationMethod = utils.findChilds(node, "CanonicalizationMethod")
209-
if (CanonicalizationMethod.length!=0) {
210-
var inclusiveNamespaces = utils.findChilds(CanonicalizationMethod[0], "InclusiveNamespaces")
211-
if (inclusiveNamespaces.length!=0) {
212-
inclusiveNamespacesPrefixList = inclusiveNamespaces[0].getAttribute('PrefixList').split(" ");
213-
}
205+
* If the inclusiveNamespacesPrefixList has not been explicitly provided then look it up in CanonicalizationMethod/InclusiveNamespaces
206+
*/
207+
if (inclusiveNamespacesPrefixList.length == 0) {
208+
var CanonicalizationMethod = utils.findChilds(node, "CanonicalizationMethod")
209+
if (CanonicalizationMethod.length != 0) {
210+
var inclusiveNamespaces = utils.findChilds(CanonicalizationMethod[0], "InclusiveNamespaces")
211+
if (inclusiveNamespaces.length != 0) {
212+
inclusiveNamespacesPrefixList = inclusiveNamespaces[0].getAttribute('PrefixList').split(" ");
213+
}
214+
}
214215
}
215216

216217
/**
217218
* If you have a PrefixList then use it and the ancestors to add the necessary namespaces
218219
*/
219-
if (inclusiveNamespacesPrefixList) {
220-
var prefixList = inclusiveNamespacesPrefixList instanceof Array ? inclusiveNamespacesPrefixList : inclusiveNamespacesPrefixList.split(' ');
221-
prefixList.forEach(function (prefix) {
222-
if (ancestorNamespaces) {
223-
ancestorNamespaces.forEach(function (ancestorNamespace) {
224-
if (prefix == ancestorNamespace.prefix) {
225-
node.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' + prefix, ancestorNamespace.namespaceURI);
226-
}
227-
})
228-
}
229-
})
230-
}
220+
if (inclusiveNamespacesPrefixList) {
221+
var prefixList = inclusiveNamespacesPrefixList instanceof Array ? inclusiveNamespacesPrefixList : inclusiveNamespacesPrefixList.split(' ');
222+
prefixList.forEach(function (prefix) {
223+
if (ancestorNamespaces) {
224+
ancestorNamespaces.forEach(function (ancestorNamespace) {
225+
if (prefix == ancestorNamespace.prefix) {
226+
node.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' + prefix, ancestorNamespace.namespaceURI);
227+
}
228+
})
229+
}
230+
})
231+
}
231232

232233
var res = this.processInner(node, [], defaultNs, defaultNsForPrefix, inclusiveNamespacesPrefixList);
233234
return res;

0 commit comments

Comments
 (0)