Guard against unclosed string crash in TOMLReader
This commit is contained in:
parent
c58ffce236
commit
512ebdfc22
2 changed files with 11 additions and 0 deletions
|
|
@ -123,6 +123,9 @@ public enum TOMLReader {
|
|||
for i in s.dropFirst().indices {
|
||||
if s[i] == "\"" { closing = i; break }
|
||||
}
|
||||
guard closing != s.startIndex else {
|
||||
throw TOMLReaderError.parseError(line: lineNumber, message: "Unterminated string in value")
|
||||
}
|
||||
let value = String(s[s.index(after: s.startIndex)..<closing])
|
||||
s = String(s[s.index(after: closing)...]).trimmingCharacters(in: .whitespaces)
|
||||
return value
|
||||
|
|
|
|||
|
|
@ -121,3 +121,11 @@ func testInvalidInput() {
|
|||
try TOMLReader.parse(input)
|
||||
}
|
||||
}
|
||||
|
||||
@Test("TOML reader rejects unclosed string")
|
||||
func testUnclosedString() {
|
||||
let input = "key = \"start"
|
||||
#expect(throws: TOMLReaderError.self) {
|
||||
try TOMLReader.parse(input)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue