Skip to content

Issue with sexagesimal support #337

@kean

Description

@kean

Hi,

I've encountered an issue because of the sexagesimal support in Yams. When you work with scalars, you can expect the Int initializer to return nil in the following scenarios:

Int("a") // return nil
Int("a:b") // returns nil

But YAMLDecoder has support for "sexagesimal" numbers (which was dropped from the YAML spec in 2009). If you use singleValueContainer and try to decode Int using YAMLDecoder, like this:

let container = try decoder.singleValueContainer()
let value = try? container.decode(Int.self)

It hits the scalar.contains(":") condition and at this point, the parser is convinced it is a number and never bails out, even if it's not a proper sexagesimal number. So the Int.self decoding produces the following result:

decodeIntFrom("a") // returns nil
decodeIntFrom("a:b") // returns `0`
decodeIntFrom("https://example.com/webhook") // returns `0`

It breaks certain assumptions that are true for JSONDecoder. I'm not sure if I did a great job describing the issue, but I suggest revising support of pre YAML 1.2 features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions