js-yaml: tabs indentation is not considered as invalid

Tab indentation will basically result as a non-char when parsing YAML.

For instance:

a:
        b:
                c: yo mamma

As tab indented comes out as:

js-yaml test.yaml 

{ a: null, b: null, c: 'yo mamma' }

It would be safer and easier to debug if the file would not be parseable on tab indent.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 2
  • Comments: 26 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Everyone who wish to invent “spec improvements” instead of following standard, can continue in fork. That’s out of this project scope.

Greetings. I am one of the creators of YAML. Tabs are not allowed in indentation and an error should happen when they are detected in a place where indentation might occur.

IMHO libyaml is the most perfect implementation of the YAML 1.1 spec (which is very close to YAML 1.2).

Here is the result of the OP test in Perl’s libyaml binding: https://gist.github.com/ac5821875eb30979f7a8 Here is the same program in Python: https://gist.github.com/582ea40dbdcd473249a4

They both throw the same error. I believe it is a wise choice to test arguable behaviors against a libyaml binding. Possibly even moreso than the spec.

FWIW, we spent every day for 3 months (circa 2003) trying to sanely allow tabs into YAML indentation. We came to the conclusion that it was an insane endeavor. (It ends up being much harder than, say, Python indentation based scoping).

Using tabs for indentation could not be done in a sane, safe and reliable fashion in YAML. We spent 3 months working on a way to use tabs in YAML during the creation of the language, and ultimately decided it was the best course of action to not allow them.

If you want to track down the emails in the yaml-core mailing list, read them all and propose a solution for tabs to work perfectly in YAML, be my guest. 😃

For now it I think that trying to support tab indentation as an option (in any implementation) would be a really bad idea.

Or, give js-yaml an option to accept TAB as a valid indentation character. Yes, the omission of tabs from the spec is explained on http://yaml.org/faq.html, but I see no harm in giving an option here in the implementation code. I use tab indentation for all other file formats in my project and would like to not be restricted from using it in “YAML” files (they wouldn’t technically be YAML anymore).

By default the library should conform to the spec of course, but that doesn’t forbid the library from providing useful non-standard options.

I’m not sure I follow? Tabs are invalid. I want to see an error when I accidentally use tab-indentation 😃