File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -277,13 +277,32 @@ - (NSArray *)attributes
277
277
278
278
- (DDXMLNode *)attributeForName : (NSString *)name
279
279
{
280
+ const xmlChar *attrName = [name xmlChar ];
281
+
280
282
xmlAttrPtr attr = ((xmlNodePtr)genericPtr)->properties ;
281
283
while (attr != NULL )
282
284
{
283
- if (xmlStrEqual ([name xmlChar ], attr->name ) )
285
+ if (attr-> ns && attr->ns -> prefix )
284
286
{
285
- return [DDXMLNode nodeWithPrimitive: (xmlKindPtr)attr];
287
+ // If the attribute name was originally something like "xml:quack",
288
+ // then attr->name is "quack" and attr->ns->prefix is "xml".
289
+ //
290
+ // So if the user is searching for "xml:quack" we need to take the prefix into account.
291
+ // Note that "xml:quack" is what would be printed if we output the attribute.
292
+
293
+ if (xmlStrQEqual (attr->ns ->prefix , attr->name , attrName))
294
+ {
295
+ return [DDXMLNode nodeWithPrimitive: (xmlKindPtr)attr];
296
+ }
286
297
}
298
+ else
299
+ {
300
+ if (xmlStrEqual (attr->name , attrName))
301
+ {
302
+ return [DDXMLNode nodeWithPrimitive: (xmlKindPtr)attr];
303
+ }
304
+ }
305
+
287
306
attr = attr->next ;
288
307
}
289
308
return nil ;
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ + (void)testNodesForXPath;
29
29
+ (void )testNSXMLBugs ;
30
30
+ (void )testInsertChild ;
31
31
+ (void )testElementSerialization ;
32
+ + (void )testAttributeWithColonInName ;
32
33
@end
33
34
34
35
@implementation DDXMLTesting
@@ -64,6 +65,7 @@ + (void)performTests
64
65
[self testNSXMLBugs ];
65
66
[self testInsertChild ];
66
67
[self testElementSerialization ];
68
+ [self testAttributeWithColonInName ];
67
69
68
70
[self tearDown ];
69
71
@@ -1513,4 +1515,23 @@ + (void)testElementSerialization
1513
1515
[pool release ];
1514
1516
}
1515
1517
1518
+ + (void )testAttributeWithColonInName
1519
+ {
1520
+ NSLog (@" Starting %@ ..." , NSStringFromSelector (_cmd));
1521
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc ] init ];
1522
+
1523
+ NSString *str = @" <artist name='Jay-Z' xml:pimp='yes' />" ;
1524
+
1525
+ NSXMLDocument *nsDoc = [[[NSXMLDocument alloc ] initWithXMLString: str options: 0 error: nil ] autorelease ];
1526
+ DDXMLDocument *ddDoc = [[[DDXMLDocument alloc ] initWithXMLString: str options: 0 error: nil ] autorelease ];
1527
+
1528
+ NSXMLNode *nsa = [[nsDoc rootElement ] attributeForName: @" xml:pimp" ];
1529
+ DDXMLNode *dda = [[ddDoc rootElement ] attributeForName: @" xml:pimp" ];
1530
+
1531
+ NSAssert (nsa != nil , @" Failed CHECK 1" );
1532
+ NSAssert (dda != nil , @" Failed test 1" );
1533
+
1534
+ [pool release ];
1535
+ }
1536
+
1516
1537
@end
You can’t perform that action at this time.
0 commit comments