We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swift version 5.1.1 (swift-5.1.1-RELEASE)
md5: 454e540889fcb0bbebb5cd7f49ac3454
relates to:
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.
XMLElement.attribute(forName🙂
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.
The text was updated successfully, but these errors were encountered:
CC @millenomi
Sorry, something went wrong.
Still not fixed in current main
main
root@0ae6b2f0fd1a:/Users/johannes/devel/swift-corelibs-foundation# swift Welcome to Swift version 5.5-dev (LLVM fb5a91b4e892ed9, Swift f17142883421ec0). Type :help for assistance. 1> import Foundation 2. #if canImport(FoundationXML) 3. import FoundationXML 4. #endif 5. 6. 7. func parseXML(_ xmlData: Data) { 8. 9. let xmlDocument = try! XMLDocument(data: xmlData) 10. 11. let rootElement = xmlDocument.rootElement()! 12. 13. let child = rootElement.children?.first(where: { $0.localName == "child" }) as! XMLElement 14. print("child attributes: \(child.attributes?.description ?? "nil")") 15. print("child attribute1: \(child.attribute(forName: "attribute1")?.description ?? "nil")") 16. } 17. 18. 19. // XML without xmlns 20. let xmlData1 = Data(""" 21. <rootElement> 22. <child attribute1="value1">Child Content</child> 23. </rootElement> 24. """.utf8) 25. 26. parseXML(xmlData1) 27. 28. 29. // XML with xmlns set to empty string 30. let xmlData2 = Data(""" 31. <rootElement> 32. <child xmlns="" attribute1="value1">Child Content</child> 33. </rootElement> 34. """.utf8) 35. 36. parseXML(xmlData2) child attributes: [ attribute1="value1"] child attribute1: attribute1="value1" child attributes: [ attribute1="value1"] child attribute1: nil xmlData1: Data = 81 bytes xmlData2: Data = 90 bytes
No branches or pull requests
Environment
Swift version 5.1.1 (swift-5.1.1-RELEASE)
Additional Detail from JIRA
md5: 454e540889fcb0bbebb5cd7f49ac3454
relates to:
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:
On macOS the output is:
And on Linux:
Also notice the additional space in front of the attribute name on Linux.
The text was updated successfully, but these errors were encountered: