3 ms·
> Well, when you say in your test file: > “test this against Go 1.20” > It interprets that as Go 1.2. Without actual YAML (“test this against Go 1.20” YAML w
by dragonwriter 3y ago
> Well, when you say in your test file:
> “test this against Go 1.20”
> It interprets that as Go 1.2.
Without actual YAML (“test this against Go 1.20” YAML would interpret as the string “test this against Go 1.20”), its hard to know the actual complaint here, but it sounds like there was a YAML file with something like:
testTarget:
- language: Go
- version: 1.20
Where the tool interpreting expected a version string in “version”, but also accepted a number and implicitly converted the number to a version string. This is not a YAML problem, this is a “code that accepts and implicitly converts invalid data problem”. Its true that a schema and validating parser would help with this, and YAML doesn’t have a broadly supported standard schema language, but I bet the real problem here was that the underlying tool was written in JavaScript, as its the main popular language where even the most naive attempt to parse what you expect to be a string value would not fail if the value was actually a number.
- SahAssar 3y agoYAML is far to helpful to convert bare strings to what it thinks is right (like 1.20 to 1.2 or no to false). It could be helped by having data validation, but the fundamental issue is that YAML does not make it clear to either human or machine what is meant or expressed. The issue is not isolated to JS either, the same could have happened in python, php, or any other untyped language.
- dragonwriter 3y ago> YAML is far to helpful to convert bare strings to what it thinks is right (like 1.20 to 1.2 or no to false Versions of the YAML standard from the last 14 years don't do the later, and supporting numbers as a basic data type is, honestly, a weird thing to harp on as “too far”. > The issue is not isolated to JS either, the same could have happened in python, php, or any other untyped language. Indexing an associative array of runtimes that is keyed by a string, or doing almost anything else that expects a string, when you get a number instead, will fail with an error in most dynamically typed languages including Python and PHP; much fewer string-expcting operating operations (and particularly not object indexing) will fail in JS with a number.
- kelnos 3y ago> This is not a YAML problem, this is a “code that accepts and implicitly converts invalid data problem”. No, this is a YAML problem, because YAML is specified to allow for unquoted strings, and then it uses heuristics to decide if you meant a string or a number or (god forbid) a boolean. So the "code that accepts..." that you're talking about is literally every conforming YAML parser out there. And they do that because the spec tells them to. So yes, it is a YAML problem. And to top that off, most of the examples and tutorials you'll find on how to use YAML don't quote their strings. I get the idea: fewer characters to type, more human readable. But god it's a minefield.