File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,25 @@ describe("XMLParser", function() {
178
178
expect ( result ) . toEqual ( expected ) ;
179
179
} ) ;
180
180
181
+ it ( "should parse XML when namespaced ignored" , function ( ) {
182
+ const xmlData = `<a:b>c</a:b><a:d/><a:e atr="sasa" boolean>` ;
183
+ const expected = {
184
+ "b" : "c" ,
185
+ "d" : "" ,
186
+ "e" : {
187
+ "@_atr" : "sasa" ,
188
+ "@_boolean" : true ,
189
+ }
190
+ } ;
191
+
192
+ const result = parser . parse ( xmlData , {
193
+ ignoreAttributes : false ,
194
+ allowBooleanAttributes : true ,
195
+ ignoreNameSpace : true ,
196
+ } ) ;
197
+ expect ( result ) . toEqual ( expected ) ;
198
+ } ) ;
199
+
181
200
it ( "should parse XML with undefined as text" , function ( ) {
182
201
const xmlData = `<tag><![CDATA[undefined]]><nested>undefined</nested></tag>` ;
183
202
const expected = {
Original file line number Diff line number Diff line change @@ -253,6 +253,7 @@ const getTraversalObj = function(xmlData, options) {
253
253
const closeIndex = result . index ;
254
254
const separatorIndex = tagExp . indexOf ( " " ) ;
255
255
let tagName = tagExp ;
256
+ let shouldBuildAttributesMap = true ;
256
257
if ( separatorIndex !== - 1 ) {
257
258
tagName = tagExp . substr ( 0 , separatorIndex ) . replace ( / \s \s * $ / , '' ) ;
258
259
tagExp = tagExp . substr ( separatorIndex + 1 ) ;
@@ -262,6 +263,7 @@ const getTraversalObj = function(xmlData, options) {
262
263
const colonIndex = tagName . indexOf ( ":" ) ;
263
264
if ( colonIndex !== - 1 ) {
264
265
tagName = tagName . substr ( colonIndex + 1 ) ;
266
+ shouldBuildAttributesMap = tagName !== result . data . substr ( colonIndex + 1 ) ;
265
267
}
266
268
}
267
269
@@ -292,7 +294,7 @@ const getTraversalObj = function(xmlData, options) {
292
294
if ( options . stopNodes . length && options . stopNodes . includes ( childNode . tagname ) ) {
293
295
childNode . startIndex = closeIndex ;
294
296
}
295
- if ( tagName !== tagExp ) {
297
+ if ( tagName !== tagExp && shouldBuildAttributesMap ) {
296
298
childNode . attrsMap = buildAttributesMap ( tagExp , options ) ;
297
299
}
298
300
currentNode . addChild ( childNode ) ;
You can’t perform that action at this time.
0 commit comments