Skip to content

Commit b65c5c6

Browse files
committed
handle path with just whitespace
1 parent 44aabdd commit b65c5c6

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

DOM/Sources/DOM.Path.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ package extension DOM {
4444
super.init()
4545
}
4646

47-
package enum Segment {
47+
package enum Segment: Equatable {
4848
case move(x: Coordinate, y: Coordinate, space: CoordinateSpace)
4949
case line(x: Coordinate, y: Coordinate, space: CoordinateSpace)
5050
case horizontal(x: Coordinate, space: CoordinateSpace)

DOM/Sources/Parser.XML.Path.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ package extension XMLParser {
5050
}
5151

5252
func parsePathSegments(_ data: String) throws -> [Segment] {
53-
guard !data.isEmpty else { return [] }
54-
5553
var segments = Array<Segment>()
5654

5755
var scanner = PathScanner(string: data)
5856

5957
scanner.charactersToBeSkipped = Foundation.CharacterSet.whitespacesAndNewlines
6058

59+
guard !scanner.isAtEnd else {
60+
return []
61+
}
62+
6163
var lastCommand: Command?
6264

6365
repeat {

DOM/Tests/Parser.XML.PathTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ final class ParserXMLPathTests: XCTestCase {
6767
XCTAssertNotEqual(Segment.move(x: 10, y: 20, space: .relative),
6868
move(10, 20, .absolute))
6969
}
70-
70+
71+
func testEmpty() throws {
72+
let parser = SwiftDrawDOM.XMLParser()
73+
XCTAssertEqual(try parser.parsePathSegments(""), [])
74+
XCTAssertEqual(try parser.parsePathSegments(" "), [])
75+
}
76+
7177
func testMove() {
7278
AssertSegmentEquals("M 10 20", move(10, 20, .absolute))
7379
AssertSegmentEquals("m 10 20", move(10, 20, .relative))

0 commit comments

Comments
 (0)