107 points · by wheresvic3 · 6y ago · 129 comments
Turns out the country code for Norway, "no", is interpreted as boolean false when unquoted in yaml.
https://github.com/adrienverge/yamllint
It can be configured to require strict string quoting.
https://yamllint.readthedocs.io/en/stable/rules.html#module-...
And to explicitly restrict bools to only `true` and `false`.
https://yamllint.readthedocs.io/en/stable/rules.html#module-...
Trying to get to almost jsonschema level without the complexity of specification and reuse with the actual code
I wrote it to read true/false, but then there were some test cases that failed. Turns out, the schema also allows yes/no and 1/0 as synonyms.
Suggesting that you were using a function as a map and "prototype" as the key seems even more made up.
If you use a template you have to put "" for strings.
That sounds like there are no human-writable formats.
> If your human-readable format requires special cases for certain keywords but treats others as strings, it's not human-readable.
That I can 100% support; sometimes needing to quote strings is a recipe for disaster.
Though: now that I think about it, most of the problems happen at the block level, not the line level. So maybe significant newlines are fine but not indentation.
A colleague spent a few hours tracking down a python bug caused by a bad merge that messed up the indent without it outright causing the code to crash, just produce wrong output. That's IMO too expensive a bug type to permit just to save a few keystrokes. But YMMV as they say.
Re: the bad merge, that can happen the other way to: this was the cause of Apple's infamous goto fail bug. I think block structured languages should do what go and some others do: braces on conditionals and loops are mandatory, parens are optional.
That’s a 1000x advantage in my book. Not mention exceptions are often avoided with a professional editor with whitespace highlighting and indentation guides.
SML and (I think) Ocaml don't, and I had assumed F# was like Ocaml, since its syntax is largely the same. In the tiny bit of F# I tried writing once I don't remember having had to pay any attention to whitespace.
Significant whitespace is one of the things I didn't enjoy about Haskell and Idris. Life's too short to indent code by hand.
Apple's infamous "goto fail" was in part caused by a mismatch between how the computer understand the block level and how the programmer did.
Is it possible to write a formatter that would fix an issue like that for yaml or python for example?
In short, there's no issue to fix.
Just not by a regex, which so many formatting tools rely upon.
int foo() {
a();
b();
c();
if (test())
doSomethingIfTest();
doSomethingUnconditionally();} def foo():
a()
b()
c()
if test():
doSomethingIfTest()
doSomethingUnconditionally()
You can still write this, which is equally garbage because a, b, and c mean nothing to me. I know you're just showing a code example, but my point is that unprofessional idiots will always write shit code, the language won't protect them from themselves.Your issue can be fixed with a linter, mine can't.
Look at this python code: https://github.com/django/django/blob/master/django/core/mai...
In my opinion, it's rather difficult to tell where one if/else block ends, and the next begins. At a glance, I couldn't even tell you how many if/else statements there are. In my opinion, braces give me a frame of reference for my eyes to lock into, even in my periphery, and give me a far better understanding of the code structure.
Structured data with only vague, and often misleading, indication of its structure is awful to work with. Sure, it's "human readable", but if your data is of any real complexity you're almost certainly better off just machine-generating it.
My personal belief is that XML was "good-enough" having been engineered for many use-cases and easy to comprehend for what it provides.
It's a tragedy that XML was abused so vigorously in the early naughts. People got so sick of it because they were compelled to edit XML manually in a text-editor with shitty to none schema support. It didn't help that the worst monstrosities of that era (soap and ws-* crap) heavily invested in turgid, badly designed XML.
I think that if there had been some more effort on tooling and good-practices, XML could have remained popular and we would not have had jason, yaml, and whatever awful thing is next.
One of the selling points of json is file size, xml started dying when people realized that more than half their bandwidth was going to xml structure rather than actual data
"Yet Another Markup Language (YAML) 1.0"
One of the things I most dislike about yaml is that they persuaded JSON to remove comments from the spec for some psuedo compatability nonsense. Without comments, json is less useful for config files and working/documented examples.
I have written a pre-parser to permit comments in JSON and for nodejs apps I use javascript as config. Naturally where security is not a concern.
Yaml always seemed like a mess to me.
Liking Toml, decent compromise.
And linux style: name space value, hash and semi for comments. Unless I really need a heirachy.
JSON5 allows comments and a few other niceties. I'd trust JSON5 parsers more than my own hand-rolled one
The human unreadability if JSON is greatly exaggerated. While you can get horrible looking JSON, you can also then pretty print it into something much better. If we could just all agree to allow comments into a spec it’d be fine.
I also detest this, but it's not really about YAML - it's ridiculous that so many of our tools no longer allow any validation / linting of files before attempting to use them; some that do require the "full service" running to provide sufficient context; even those that don't don't always give good (i.e. consistent, structured) errors. This problem would remain if the format was JSON, TOML, or even XML when working without schemas for every namespace.
The worst is the tools that layer Jinja on top of the YAML (Salt/Ansible/Puppet) which is basically impossible to validate statically. At least with GitLab, Docker Compose, and Kubernetes I have some hope - but integration into other tools is awful.
> Don’t get me wrong, it’s not like YAML is absolutely terrible – it’s probably better than using JSON – but it’s not exactly great either. There are some drawbacks and surprises that are not at all obvious at first, and there are a number of better alternatives such as TOML and other more specialized formats.
> One good alternative might be to just use commandline flags.
> If you must use YAML then I recommend you use StrictYAML, which removes some (though not all) of the more hairy parts.
(I do agree YAML is in retrospect a mistake. The reasons why remind me in some ways of the problems with Markdown).
(Oddly, I can't seem to find an up to date TOML parser in ruby that supports the 1.0 spec...)
YAML is a complex and unintuitive mess that allows doing every thing in a million ways. I’m surprised it ever got so much traction. TOML is a breath of fresh air next to it.
That's false. https://metacpan.org/pod/JSON::XS#JSON-and-YAML
{"3":{"14159":"pi"}}
Otherwise I think TOML is great."Who approved this?!"
I can't imagine the cluster fuck of ideas in a person's head to lead to thinking that this was an ok design for a configuration file. The person who designed this and I just don't live on the same planet.
And here I thought the reason I didn't use YAML was because the syntax looked stupid.
A more conservative implementation wouldn't have that particular vulnerability.
!!python/object/apply:os.system
args: ['ls /']
Who put that backdoor in?Authors of some libraries did not consider the security implications of the object serialisation part of the spec. I assign the blame to them for not looking beyond their own limited horizon, metaphorically speaking. When they made their libraries, the reference implementation was already available and it was secure by default.
That does make it closer to an unfortunate (but entirely avoidable) accident rather than what you believe, that evil people maliciously and intentionally added a backdoor. You can keep believing it, but that does not make it any more true.
Debugging nearly invisible indentation problems can be such a pain.
however, this biggest issue why YAML is my least favorite config format. unquoted strings with colons is another top one.
When I first saw YAML, it was nice but it felt a bit too complicated.
All I really want is Indented JSON. New lines instead of commas. That’s it.
Json is fast to parse. See simdjson doing it at > 2.5GB/s. One can’t do this with YAML where no could mean many things.
And god I hate k8s for their bajillion yaml configs. Thank god for jsonnet that can dump to yaml. Jsonnet is truly nice and makes working with json like configs a pleasure.
Serious question: why doesn’t this language space have a universally adopted candidate like SQL?
But everyone thought "that's too complex" and so reinvented something simpler. Then kept adding features, and more features, and now YAML is more complicated than XML.
This process will repeat ad infinitum.
It is so ironic to see these fads come and go, and then one wonders why we are so cinic regarding newcomers.
JSON is pretty common, and liveable with a few conservative extensions like comment support. But the extensions haven't gained a lot of traction yet.
TOML is mentioned but I do not see wide adoption, e.g. no up-to-date Java or similar implementation. (https://github.com/toml-lang/toml/wiki#implementations)
Additionally I think TOML is more verbose compared to YAML but avoids the indentation ugliness.
Python gives you all the power of scripting including validation and json gives you the easily readable format for both humans and machines. Great for knowing exactly what the settings evaluated as.
And when you don't need the power of full expressive python script, you can just json.dump() a python dictionary and be done with it.
I've also used sqlite as a config file format and that is very polite and easily read from anything I use.
There are tons of IDEs supporting XML (syntax highlight & collapsing brackets, etc...). XML schema is also great to ensure the config is conforming. I keep thinking we are trying to reinvent a worse wheel here.
yaml.load is now a wrapper around yaml.safe_load that negates the risks he highlights
If yaml is not working for you have to search a serializer format that fit in your project.
There is not silver bullet.
If I need a serializer format, it's not human-readable/writable, and I might as well have something like XML or s-exp that are easier for many tools to work with, more easily composable, easier to generate automatically, etc.
> There is not silver bullet.
This phrase needs to be retired. It's true, but invoked far too often to excuse shit bullets.
I beg to differ.