Open
Description
Previous ID | SR-11606 |
Radar | None |
Original Reporter | @florianreinhart |
Type | Bug |
Environment
Swift version 5.1.1 (swift-5.1.1-RELEASE)
Additional Detail from JIRA
Votes | 0 |
Component/s | Foundation |
Labels | Bug, Linux |
Assignee | None |
Priority | Medium |
md5: 454e540889fcb0bbebb5cd7f49ac3454
relates to:
- SR-10424 Parity: XMLElement: XML Namespaces
Issue Description:
I ran into a regression probably introduced in FoundationXML bundled with Swift 5.1 by PR2313.
XMLElement.attribute(forName:)
does not return an attribute if xmlns is set to an empty string in the element.
The following program demonstrates the issue:
import Foundation
#if canImport(FoundationXML)
import FoundationXML
#endif
func parseXML(_ xmlData: Data) {
let xmlDocument = try! XMLDocument(data: xmlData)
let rootElement = xmlDocument.rootElement()!
let child = rootElement.children?.first(where: { $0.localName == "child" }) as! XMLElement
print("child attributes: \(child.attributes?.description ?? "nil")")
print("child attribute1: \(child.attribute(forName: "attribute1")?.description ?? "nil")")
}
// XML without xmlns
let xmlData1 = Data("""
<rootElement>
<child attribute1="value1">Child Content</child>
</rootElement>
""".utf8)
parseXML(xmlData1)
// XML with xmlns set to empty string
let xmlData2 = Data("""
<rootElement>
<child xmlns="" attribute1="value1">Child Content</child>
</rootElement>
""".utf8)
parseXML(xmlData2)
On macOS the output is:
child attributes: [attribute1="value1"]
child attribute1: attribute1="value1"
child attributes: [attribute1="value1"]
child attribute1: attribute1="value1"
And on Linux:
child attributes: [ attribute1="value1"]
child attribute1: attribute1="value1"
child attributes: [ attribute1="value1"]
child attribute1: nil
Also notice the additional space in front of the attribute name on Linux.