From 6c9578a185313c732999f1054a598e1d169974ce Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 16 Mar 2022 17:03:38 -0700 Subject: [PATCH 1/4] Add failing test --- test/c14n-non-exclusive-unit-test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/c14n-non-exclusive-unit-test.js b/test/c14n-non-exclusive-unit-test.js index 49c837b8..4654675d 100644 --- a/test/c14n-non-exclusive-unit-test.js +++ b/test/c14n-non-exclusive-unit-test.js @@ -176,3 +176,11 @@ exports["C14n: Don't redeclare an attribute's namespace prefix if already in sco test_C14nCanonicalization(test, xml, xpath, expected); } + +exports["C14n: Don't declare an attribute's namespace prefix if in scope from parent"] = function(test) { + var xml = "" + var xpath = "/root/child1"; + var expected = ""; + + test_C14nCanonicalization(test, xml, xpath, expected); +} From 27ca996f24acd5e37a54444d4d9cd0fbbf41bed5 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Thu, 14 Apr 2022 09:36:04 -0700 Subject: [PATCH 2/4] Fix spec by initializing `prefixesInScope` from `ancestorNamespaces` --- lib/c14n-canonicalization.js | 8 +++++++- test/c14n-non-exclusive-unit-test.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/c14n-canonicalization.js b/lib/c14n-canonicalization.js index ac533481..6eee30ef 100644 --- a/lib/c14n-canonicalization.js +++ b/lib/c14n-canonicalization.js @@ -208,7 +208,13 @@ C14nCanonicalization.prototype.process = function(node, options) { var defaultNsForPrefix = options.defaultNsForPrefix || {}; var ancestorNamespaces = options.ancestorNamespaces || []; - var res = this.processInner(node, [], defaultNs, defaultNsForPrefix, ancestorNamespaces); + var prefixesInScope = []; + for (var i = 0; i < ancestorNamespaces.length; i++) { + prefixesInScope.push(ancestorNamespaces[i].prefix) + } + + console.log({prefixesInScope}) + var res = this.processInner(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces); return res; }; diff --git a/test/c14n-non-exclusive-unit-test.js b/test/c14n-non-exclusive-unit-test.js index 4654675d..e4a45e22 100644 --- a/test/c14n-non-exclusive-unit-test.js +++ b/test/c14n-non-exclusive-unit-test.js @@ -180,7 +180,7 @@ exports["C14n: Don't redeclare an attribute's namespace prefix if already in sco exports["C14n: Don't declare an attribute's namespace prefix if in scope from parent"] = function(test) { var xml = "" var xpath = "/root/child1"; - var expected = ""; + var expected = ''; test_C14nCanonicalization(test, xml, xpath, expected); } From 55f3c6d927e45fcd0535ff7fae6e607d84425765 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Thu, 14 Apr 2022 09:45:59 -0700 Subject: [PATCH 3/4] Remove accidental `console.log` --- lib/c14n-canonicalization.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/c14n-canonicalization.js b/lib/c14n-canonicalization.js index 6eee30ef..95d90475 100644 --- a/lib/c14n-canonicalization.js +++ b/lib/c14n-canonicalization.js @@ -213,7 +213,6 @@ C14nCanonicalization.prototype.process = function(node, options) { prefixesInScope.push(ancestorNamespaces[i].prefix) } - console.log({prefixesInScope}) var res = this.processInner(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces); return res; }; From 9e3fc69d45c8b2f2f7d2da9a9cb5ffb55e06f0b7 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Thu, 14 Apr 2022 09:46:47 -0700 Subject: [PATCH 4/4] Add `;` for consistency --- lib/c14n-canonicalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/c14n-canonicalization.js b/lib/c14n-canonicalization.js index 95d90475..9d0419b4 100644 --- a/lib/c14n-canonicalization.js +++ b/lib/c14n-canonicalization.js @@ -210,7 +210,7 @@ C14nCanonicalization.prototype.process = function(node, options) { var prefixesInScope = []; for (var i = 0; i < ancestorNamespaces.length; i++) { - prefixesInScope.push(ancestorNamespaces[i].prefix) + prefixesInScope.push(ancestorNamespaces[i].prefix); } var res = this.processInner(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces);