diff --git a/Sources/TOMLDecoder/Parsing/Parser.swift b/Sources/TOMLDecoder/Parsing/Parser.swift index 8b0d71a..e3da4d5 100644 --- a/Sources/TOMLDecoder/Parsing/Parser.swift +++ b/Sources/TOMLDecoder/Parsing/Parser.swift @@ -1343,6 +1343,9 @@ extension Token { } // Single zero is allowed to continue to the main loop } + guard index < text.upperBound else { + throw TOMLError(.invalidInteger(context: context, lineNumber: lineNumber, reason: "expected digit after base prefix")) + } while index < text.upperBound { let ch = bytes[index] diff --git a/Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift b/Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift index 7100229..64e4093 100644 --- a/Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift +++ b/Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift @@ -52,4 +52,11 @@ struct TOMLTableKeyMembershipTests { _ = try Dictionary(TOMLTable(source: "x = +\n")) } } + + @Test + func basePrefixOnlyIntegerThrowsWithoutTrapping() throws { + #expect(throws: TOMLError.self) { + _ = try Dictionary(TOMLTable(source: "x = 0x\n")) + } + } }