Skip to content

Commit

Permalink
Fix crash on decoding partial YAML (#1)
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
kkebo committed May 5, 2023
1 parent 1628bc6 commit e79d297
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Sources/UniYAML/Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ public struct UniYAML {
return nil
}
_ = parseIndent(stream, index: &index)
guard index < stream.endIndex else {
return nil
}
var search = Range(uncheckedBounds: (index, stream.endIndex))
var location = search
var fragments = ""
Expand Down
7 changes: 7 additions & 0 deletions Tests/UniYAMLTests/UniYAMLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class UniYAMLTests: XCTestCase {
("testYAMLUnexpectedColon", testYAMLUnexpectedColon),
("testYAMLUnexpectedBrace", testYAMLUnexpectedBrace),
("testYAMLUnexpectedEnd", testYAMLUnexpectedEnd),
("testPartialYAML", testPartialYAML),
]

let types = "---\n\nsimple string: a text\nquoted string: 'john ''beatle''\n lennon'\nsplit string: >\n two\n words\nrows: |\n first\n second\n last\nint: -12345\nuint: 67890\ndouble: 3.14159265\npositive: yes\nnegative: off\n"
Expand Down Expand Up @@ -456,4 +457,10 @@ classic:
XCTAssert(obj == nil && err.hasPrefix("unexpected stream end"))
}

func testPartialYAML() throws {
let yaml = "a: "
let obj = try UniYAML.decode(yaml)
XCTAssertEqual(obj, nil)
}

}

0 comments on commit e79d297

Please sign in to comment.