yaml-spec icon indicating copy to clipboard operation
yaml-spec copied to clipboard

YAML 1.2 Inf/NaN

Open perlpunk opened this issue 6 years ago • 1 comments

The YAML JSON Schema mentions .inf and .nan: http://yaml.org/spec/1.2/spec.html#id2804092 10.2.1.4. Floating Point but doesn't list them in the http://yaml.org/spec/1.2/spec.html#id2803036 10.2.2. Tag Resolution list.

The Core Schema lists them: http://yaml.org/spec/1.2/spec.html#id2805071 10.3.2. Tag Resolution

So are they meant to be supported in the JSON Schema or not?

perlpunk avatar Apr 21 '18 17:04 perlpunk

To me, this behavior, though potentially surprising, is not ambiguous. The JSON schema doesn't allow e.g. .nan, but it does allow e.g. !!float .nan. There's probably a conversation to be had here about the role and purpose of the JSON schema, but I don't think it should result in spec changes for 1.2.1.

The root cause of the issue is that, as described in the spec, a global tag has a single universal set of canonical forms, even though different schemas may have different tag resolution rules. As a result, the 1.2 JSON schema can represent data that cannot be represented in JSON, which seems contrary to the intent of the JSON schema. The only ways I can see to address this would be either to narrow the definition of the float tag to forbid NaN and Infinity or to say that a tag's set of canonical forms may depend on the schema and not merely the tag itself. Either would have broader implications.

Thom1729 avatar Aug 27 '21 17:08 Thom1729