Skip to content

SR-9758: XMLParser.parse() should return false if abortParsing() is called. #1867

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 3 commits into from
Jan 31, 2019
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
14 changes: 6 additions & 8 deletions Foundation/XMLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -465,16 +465,14 @@ open class XMLParser : NSObject {
}

internal func _handleParseResult(_ parseResult: Int32) -> Bool {
return true
/*
var result = true
if parseResult != 0 {
if parseResult != -1 {
// TODO: determine if this result is a fatal error from libxml via the CF implementations
if parseResult == 0 {
return true
} else {
if _parserError == nil {
_parserError = NSError(domain: XMLParser.errorDomain, code: Int(parseResult))
}
}
return result
*/
return false
}

internal func parseData(_ data: Data) -> Bool {
Expand Down
13 changes: 13 additions & 0 deletions TestFoundation/TestXMLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TestXMLParser : XCTestCase {
("test_withData", test_withData),
("test_withDataEncodings", test_withDataEncodings),
("test_withDataOptions", test_withDataOptions),
("test_sr9758_abortParsing", test_sr9758_abortParsing),
]
}

Expand Down Expand Up @@ -141,4 +142,16 @@ class TestXMLParser : XCTestCase {
XCTAssertTrue(res)
}

func test_sr9758_abortParsing() {
class Delegate: NSObject, XMLParserDelegate {
func parserDidStartDocument(_ parser: XMLParser) { parser.abortParsing() }
}
let xml = TestXMLParser.xmlUnderTest(encoding: .utf8)
let parser = XMLParser(data: xml.data(using: .utf8)!)
let delegate = Delegate()
parser.delegate = delegate
XCTAssertFalse(parser.parse())
XCTAssertNotNil(parser.parserError)
}

}