Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with sexagesimal support #337

Closed
kean opened this issue Dec 19, 2021 · 1 comment · Fixed by #409
Closed

Issue with sexagesimal support #337

kean opened this issue Dec 19, 2021 · 1 comment · Fixed by #409

Comments

@kean
Copy link

kean commented Dec 19, 2021

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.

@kean
Copy link
Author

kean commented Dec 19, 2021

I found the following note on wiki:

In version 1.1[17] of the YAML data storage format, sexagesimals are supported for plain scalars, and formally specified both for integers[18] and floating point numbers.[19] This has led to confusion, as e.g. some MAC addresses would be recognised as sexagesimals and loaded as integers, where others were not and loaded as strings. In YAML 1.2 support for sexagesimals was dropped.[20]

That's basically exactly the issue I'm encountering. But I think it's a bit worse in Yams because it thinks that anything with ":" is an integer, e.g. "https://example.com/webhook" is an integer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant