Skip to content

Commit 49f93d8

Browse files
authored
Merge pull request #242 from mthadley/canonicalization-with-ancestor-namespaces
Correct behavior for XML canonicalization with namespaces and nested elements
2 parents a82b9eb + 9e3fc69 commit 49f93d8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/c14n-canonicalization.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ C14nCanonicalization.prototype.process = function(node, options) {
208208
var defaultNsForPrefix = options.defaultNsForPrefix || {};
209209
var ancestorNamespaces = options.ancestorNamespaces || [];
210210

211-
var res = this.processInner(node, [], defaultNs, defaultNsForPrefix, ancestorNamespaces);
211+
var prefixesInScope = [];
212+
for (var i = 0; i < ancestorNamespaces.length; i++) {
213+
prefixesInScope.push(ancestorNamespaces[i].prefix);
214+
}
215+
216+
var res = this.processInner(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces);
212217
return res;
213218
};
214219

test/c14n-non-exclusive-unit-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,11 @@ exports["C14n: Don't redeclare an attribute's namespace prefix if already in sco
176176

177177
test_C14nCanonicalization(test, xml, xpath, expected);
178178
}
179+
180+
exports["C14n: Don't declare an attribute's namespace prefix if in scope from parent"] = function(test) {
181+
var xml = "<root xmlns:aaa='bbb'><child1><child2><child3 aaa:foo='bar'></child3></child2></child1></root>"
182+
var xpath = "/root/child1";
183+
var expected = '<child1 xmlns:aaa="bbb"><child2><child3 aaa:foo="bar"></child3></child2></child1>';
184+
185+
test_C14nCanonicalization(test, xml, xpath, expected);
186+
}

0 commit comments

Comments
 (0)