Skip to content

SR-7570: Initializing XMLDocument crashes on Linux with nodePreserveAll #1551

New issue

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

Merged
merged 1 commit into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreFoundation/Parsing.subproj/CFXMLInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ _CFXMLNodePtr _CFXMLNodeHasProp(_CFXMLNodePtr node, const char* propertyName) {
return xmlHasProp(node, (const xmlChar*)propertyName);
}

_CFXMLDocPtr _CFXMLDocPtrFromDataWithOptions(CFDataRef data, int options) {
_CFXMLDocPtr _CFXMLDocPtrFromDataWithOptions(CFDataRef data, unsigned int options) {
uint32_t xmlOptions = 0;

if ((options & _kCFXMLNodePreserveWhitespace) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion CoreFoundation/Parsing.subproj/CFXMLInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ CFStringRef _Nullable _CFXMLCopyPathForNode(_CFXMLNodePtr node);

_CFXMLNodePtr _Nullable _CFXMLNodeHasProp(_CFXMLNodePtr node, const char* propertyName);

_CFXMLDocPtr _CFXMLDocPtrFromDataWithOptions(CFDataRef data, int options);
_CFXMLDocPtr _CFXMLDocPtrFromDataWithOptions(CFDataRef data, unsigned int options);

CFStringRef _Nullable _CFXMLNodeCopyLocalName(_CFXMLNodePtr node);
CFStringRef _Nullable _CFXMLNodeCopyPrefix(_CFXMLNodePtr node);
Expand Down
2 changes: 1 addition & 1 deletion Foundation/XMLDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ open class XMLDocument : XMLNode {
@abstract Returns a document created from data. Parse errors are returned in <tt>error</tt>.
*/
public init(data: Data, options mask: XMLNode.Options = []) throws {
let docPtr = _CFXMLDocPtrFromDataWithOptions(data._cfObject, Int32(mask.rawValue))
let docPtr = _CFXMLDocPtrFromDataWithOptions(data._cfObject, UInt32(mask.rawValue))
super.init(ptr: _CFXMLNodePtr(docPtr))

if mask.contains(.documentValidate) {
Expand Down
17 changes: 17 additions & 0 deletions TestFoundation/TestXMLDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TestXMLDocument : LoopbackServerTest {
("test_createElement", test_createElement),
("test_addNamespace", test_addNamespace),
("test_removeNamespace", test_removeNamespace),
("test_optionPreserveAll", test_optionPreserveAll),
]
}

Expand Down Expand Up @@ -510,6 +511,22 @@ class TestXMLDocument : LoopbackServerTest {

XCTAssert(doc.rootElement()?.elements(forLocalName: "prop", uri: "DAV:").first?.name == "D:prop", "failed to get elements, got \(doc.rootElement()?.elements(forLocalName: "prop", uri: "DAV:").first as Any)")
}

func test_optionPreserveAll() {
let xmlString = """
<?xml version="1.0" encoding="UTF-8"?>
<document>
</document>
"""

let data = xmlString.data(using: .utf8)!
guard let document = try? XMLDocument(data: data, options: .nodePreserveAll) else {
XCTFail("XMLDocument with options .nodePreserveAll")
return
}
let expected = xmlString.lowercased() + "\n"
XCTAssertEqual(expected, String(describing: document))
}
}

fileprivate extension XMLNode {
Expand Down