Skip to content

Toml.parse accepts out of range dates and times #9647

Closed

Description

@devangpratap

Toml.parse doesn't range-check dates and times. Local dates and times with an impossible month, day, hour, minute or second are accepted as is, and an offset date-time with an impossible day or hour is silently moved to a later date. On main (and on v4/next-minor, where it returns Success):

import * as Toml from "effect/encoding/Toml"

Toml.parse("a = 1979-02-30T07:32:00Z")
// { a: 1979-03-02T07:32:00.000Z }

Toml.parse("a = 1979-13-01")
// { a: "1979-13-01" }

Toml.parse("a = 24:00:00")
// { a: "24:00:00" }

TOML 1.0 requires RFC 3339 values, so all three should fail. The offset case is the worst one, since the document parses and the config just gets the wrong date. Date rolls Feb 30 over to Mar 2 instead of returning an invalid date, so the existing isNaN check never fires.

Running the toml-test 1.0 suite, 21 of the invalid files Toml.parse accepts are of this kind (feb-30, month-over, hour-over, minute-over and so on under datetime, local-date, local-datetime and local-time).

I have a small fix with a test and will open a PR against v4/next-minor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions