fix: reject offset on a bare local time or date - #59
Open
hong4rc wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
parse()accepts a TOML time-of-day or date that carries a timezone offset (Zor±HH:MM) and silently corrupts the value instead of rejecting it. Per TOML, an offset is only valid on an offset-date-time (a full date and time);local-time,local-date, andlocal-date-timehave no offset.08:30:00-07:0015:30:00(corrupted)07:32:00Z07:32:00(Z dropped)1979-05-27Z1979-05-27(Z dropped)1979-05-27T07:32:00-07:0007:32:00/1979-05-27Why it happens
In
TomlDate's constructor (src/date.ts), the offset capture group (match[3]) is applied whenever it's present, with no check that a date (match[1]) and a time (match[2]) accompany it.super(...)then builds a validDateshifted to UTC, but the value is classified as a local time/date, so reading it back yields the UTC-shifted instant — a silently wrong value, and an invalid construct accepted.Fix
Reject an offset that isn't on a full date-time —
match[3]present whilematch[1](date) ormatch[2](time) is missing — alongside the existing rollover-hours guard. Offset-date-times and bare local-time/local-date are unaffected.Tests
Added
07:32:00Z,07:32:00-07:00, and1979-05-27Zto the "rejects invalid dates" suite. Full suite passes (141 tests).