Skip to content
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
3 changes: 3 additions & 0 deletions Sources/TOMLDecoder/Parsing/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,9 @@ extension Token {
resultCodeUnits.append(bytes[index])
index = text.index(after: index)
}
guard index < text.upperBound else {
throw TOMLError(.invalidInteger(context: context, lineNumber: lineNumber, reason: "expected digit after sign"))
}

if bytes[index] == CodeUnits.underscore {
throw TOMLError(.invalidInteger(context: context, lineNumber: lineNumber, reason: "cannot start with a '_'"))
Expand Down
7 changes: 7 additions & 0 deletions Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ struct TOMLTableKeyMembershipTests {
try inlineTable.string(forKey: "x")
}
}

@Test
func signOnlyIntegerThrowsWithoutTrapping() throws {
#expect(throws: TOMLError.self) {
_ = try Dictionary(TOMLTable(source: "x = +\n"))
}
}
}
Loading