1
0
Fork 0

Guard against unclosed string crash in TOMLReader

This commit is contained in:
Brendan Szymanski 2026-07-01 13:28:40 -04:00
parent c58ffce236
commit 512ebdfc22
2 changed files with 11 additions and 0 deletions

View file

@ -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

View file

@ -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)
}
}