@@ -78,19 +78,13 @@ function isPrefixInScope(prefixesInScope, prefix, namespaceURI)
78
78
* @return {String }
79
79
* @api private
80
80
*/
81
- ExclusiveCanonicalization . prototype . renderNs = function ( node ,
82
- prefixesInScope ,
83
- defaultNs ,
84
- defaultNsForPrefix ,
85
- inclusiveNamespacesPrefixList ,
86
- ancestorNamespaces ,
87
- topNode
88
- ) {
81
+ ExclusiveCanonicalization . prototype . renderNs = function ( node , prefixesInScope , defaultNs , defaultNsForPrefix , inclusiveNamespacesPrefixList ) {
89
82
var a , i , p , attr
90
83
, res = [ ]
91
84
, newDefaultNs = defaultNs
92
85
, nsListToRender = [ ]
93
86
, currNs = node . namespaceURI || "" ;
87
+
94
88
//handle the namespaceof the node itself
95
89
if ( node . prefix ) {
96
90
if ( ! isPrefixInScope ( prefixesInScope , node . prefix , node . namespaceURI || defaultNsForPrefix [ node . prefix ] ) ) {
@@ -104,57 +98,23 @@ ExclusiveCanonicalization.prototype.renderNs = function(node,
104
98
res . push ( ' xmlns="' , newDefaultNs , '"' ) ;
105
99
}
106
100
107
- if ( topNode ) {
108
- for ( var j = 0 ; j < ancestorNamespaces . length ; j ++ ) {
109
- var ancestorNs = ancestorNamespaces [ j ] ;
110
- for ( var k = 0 ; k < inclusiveNamespacesPrefixList . length ; k ++ ) {
111
- var inclusiveNs = inclusiveNamespacesPrefixList [ k ] ;
112
- if ( ancestorNs . prefix === inclusiveNs && ! isPrefixInScope ( prefixesInScope , ancestorNs . prefix , ancestorNs . namespaceURI ) ) {
113
- nsListToRender . push ( { "prefix" : ancestorNs . prefix , "namespaceURI" : ancestorNs . namespaceURI } ) ;
114
- prefixesInScope . push ( { "prefix" : ancestorNs . prefix , "namespaceURI" : ancestorNs . namespaceURI } ) ;
115
- }
116
- }
117
- }
118
- }
119
-
120
101
//handle the attributes namespace
121
102
if ( node . attributes ) {
122
103
for ( i = 0 ; i < node . attributes . length ; ++ i ) {
123
104
attr = node . attributes [ i ] ;
124
105
125
-
126
106
//handle all prefixed attributes that are included in the prefix list and where
127
107
//the prefix is not defined already
128
- if ( attr . prefix &&
129
- ! isPrefixInScope ( prefixesInScope , attr . localName , attr . value ) &&
130
- ( inclusiveNamespacesPrefixList . indexOf ( attr . localName ) >= 0 ) ) {
108
+ if ( attr . prefix && ! isPrefixInScope ( prefixesInScope , attr . localName , attr . value ) && inclusiveNamespacesPrefixList . indexOf ( attr . localName ) >= 0 ) {
131
109
nsListToRender . push ( { "prefix" : attr . localName , "namespaceURI" : attr . value } ) ;
132
110
prefixesInScope . push ( { "prefix" : attr . localName , "namespaceURI" : attr . value } ) ;
133
111
}
134
112
135
113
//handle all prefixed attributes that are not xmlns definitions and where
136
114
//the prefix is not defined already
137
- if ( attr . prefix && attr . prefix !== "xmlns" && attr . prefix !== "xml" ) {
138
- var artificiallyIntroduced = false ;
139
- if ( attr . namespaceURI === undefined ) {
140
- //This could mean that the namespace Uri has been reset to "", or it could mean we have artificially
141
- //introduced it because it was in inclusiveNamespacePrefixList
142
- if ( inclusiveNamespacesPrefixList . indexOf ( attr . prefix ) >= 0 ) {
143
- for ( var j = 0 ; j < ancestorNamespaces . length ; j ++ ) {
144
- var ancestorNs = ancestorNamespaces [ j ] ;
145
- if ( ancestorNs . prefix === attr . prefix ) {
146
- artificiallyIntroduced = true ;
147
- break ;
148
- }
149
- }
150
- }
151
- }
152
- if ( ! artificiallyIntroduced ) {
153
- if ( ! isPrefixInScope ( prefixesInScope , attr . prefix , attr . namespaceURI ) ) {
154
- nsListToRender . push ( { "prefix" : attr . prefix , "namespaceURI" : attr . namespaceURI || defaultNsForPrefix [ attr . prefix ] } ) ;
155
- prefixesInScope . push ( { "prefix" : attr . prefix , "namespaceURI" : attr . namespaceURI || defaultNsForPrefix [ attr . prefix ] } ) ;
156
- }
157
- }
115
+ if ( attr . prefix && ! isPrefixInScope ( prefixesInScope , attr . prefix , attr . namespaceURI ) && attr . prefix != "xmlns" && attr . prefix != "xml" ) {
116
+ nsListToRender . push ( { "prefix" : attr . prefix , "namespaceURI" : attr . namespaceURI } ) ;
117
+ prefixesInScope . push ( { "prefix" : attr . prefix , "namespaceURI" : attr . namespaceURI } ) ;
158
118
}
159
119
}
160
120
}
@@ -172,23 +132,18 @@ ExclusiveCanonicalization.prototype.renderNs = function(node,
172
132
return { "rendered" : res . join ( "" ) , "newDefaultNs" : newDefaultNs } ;
173
133
} ;
174
134
175
- ExclusiveCanonicalization . prototype . processInner = function ( node ,
176
- prefixesInScope ,
177
- defaultNs ,
178
- defaultNsForPrefix ,
179
- inclusiveNamespacesPrefixList ,
180
- ancestorNamespaces ,
181
- topNode ) {
135
+ ExclusiveCanonicalization . prototype . processInner = function ( node , prefixesInScope , defaultNs , defaultNsForPrefix , inclusiveNamespacesPrefixList ) {
136
+
182
137
if ( node . nodeType === 8 ) { return this . renderComment ( node ) ; }
183
138
if ( node . data ) { return utils . encodeSpecialCharactersInText ( node . data ) ; }
184
139
185
140
var i , pfxCopy
186
- , ns = this . renderNs ( node , prefixesInScope , defaultNs , defaultNsForPrefix , inclusiveNamespacesPrefixList , ancestorNamespaces , topNode )
141
+ , ns = this . renderNs ( node , prefixesInScope , defaultNs , defaultNsForPrefix , inclusiveNamespacesPrefixList )
187
142
, res = [ "<" , node . tagName , ns . rendered , this . renderAttrs ( node , ns . newDefaultNs ) , ">" ] ;
188
143
189
144
for ( i = 0 ; i < node . childNodes . length ; ++ i ) {
190
145
pfxCopy = prefixesInScope . slice ( 0 ) ;
191
- res . push ( this . processInner ( node . childNodes [ i ] , pfxCopy , ns . newDefaultNs , defaultNsForPrefix , inclusiveNamespacesPrefixList , ancestorNamespaces , false ) ) ;
146
+ res . push ( this . processInner ( node . childNodes [ i ] , pfxCopy , ns . newDefaultNs , defaultNsForPrefix , inclusiveNamespacesPrefixList ) ) ;
192
147
}
193
148
194
149
res . push ( "</" , node . tagName , ">" ) ;
@@ -242,10 +197,9 @@ ExclusiveCanonicalization.prototype.process = function(node, options) {
242
197
var inclusiveNamespacesPrefixList = options . inclusiveNamespacesPrefixList || [ ] ;
243
198
var defaultNs = options . defaultNs || "" ;
244
199
var defaultNsForPrefix = options . defaultNsForPrefix || { } ;
245
- var ancestorNamespaces = options . ancestorNamespaces || [ ] ;
246
200
if ( ! ( inclusiveNamespacesPrefixList instanceof Array ) ) { inclusiveNamespacesPrefixList = inclusiveNamespacesPrefixList . split ( ' ' ) ; }
247
201
248
- var res = this . processInner ( node , [ ] , defaultNs , defaultNsForPrefix , inclusiveNamespacesPrefixList , ancestorNamespaces , true ) ;
202
+ var res = this . processInner ( node , [ ] , defaultNs , defaultNsForPrefix , inclusiveNamespacesPrefixList ) ;
249
203
return res ;
250
204
} ;
251
205
0 commit comments