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.
Hi,
I've encountered an issue because of the sexagesimal support in Yams. When you work with scalars, you can expect the
Intinitializer to returnnilin the following scenarios:But
YAMLDecoderhas support for "sexagesimal" numbers (which was dropped from the YAML spec in 2009). If you usesingleValueContainerand try to decodeIntusingYAMLDecoder, like this: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 theInt.selfdecoding produces the following result: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.