diff --git a/examples/canonicalization_test.go b/examples/canonicalization_test.go index 498036d..6baab5e 100644 --- a/examples/canonicalization_test.go +++ b/examples/canonicalization_test.go @@ -168,6 +168,9 @@ var example37SubsetExpression = `` +var exampleGHIssue50Output = `` + type exampleXML struct { input string output string @@ -190,6 +193,7 @@ func TestCanonicalizationExamples(t *testing.T) { // http://stackoverflow.com/questions/6002619/unmarshal-an-iso-8859-1-xml-input-in-go // "(Example 3.6)": {input: example36Input, output: example36Output}, // "(Example 3.7)": {input: example37Input, output: example37Output, expression: example37SubsetExpression}, + "(Example from GitHub Issue #50)": {input: exampleGHIssue50Input, output: exampleGHIssue50Output}, } for description, test := range cases { Convey(fmt.Sprintf("When transformed %s", description), func() { diff --git a/exclusivecanonicalization.go b/exclusivecanonicalization.go index 2df61d6..94e4310 100644 --- a/exclusivecanonicalization.go +++ b/exclusivecanonicalization.go @@ -161,7 +161,9 @@ func (e ExclusiveCanonicalization) processRecursive(node *etree.Element, newDefaultNS, newPrefixesInScope := e.renderAttributes(node, prefixesInScope, defaultNS) - for _, child := range node.Child { + for i := 0; i < len(node.Child); i++ { + child := node.Child[i] + oldNamespaces := e.namespaces e.namespaces = copyNamespace(oldNamespaces) @@ -169,6 +171,7 @@ func (e ExclusiveCanonicalization) processRecursive(node *etree.Element, case *etree.Comment: if !e.WithComments { removeTokenFromElement(etree.Token(child), node) + i-- } case *etree.Element: e.processRecursive(child, newPrefixesInScope, newDefaultNS)