Exclamation marks in YAML #334

andyw8 opened this Issue May 31, 2013 · 10 comments


None yet

5 participants


Apologies for posting a question rather than an actual issue, but what do the exclamation marks in the YAML signify? e.g.

      default: ! '%d-%m-%Y'
      long: ! '%B %d, %Y'
      short: ! '%d %b'

I've seen this StackOverflow post but it doesn't really make it clear.


That's was actually the post I intended to link to. I see that it's a "Non-specific tag", but I don't understand what that means. The YAML spec isn't very readable if you're not already familiar with the terminology.


But don't the quote marks cause it to be treated as a string anyway?


Also, I can't see a general rule for when the ! is required. In most cases it seems to exist if the value has a token at the beginning, but errors.templates.body and last_word_connector also have it.


Interestingly rails itself does not use the exclamation marks: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml

It seems they were introduced by this commit: 21c8006#rails/locale/en-US.yml

which used Psych to clean up the locale files and make them "100% YAML 1.0 compatible in the strictest sense"


Commit mentioned by @digitalfrost was created in Jan 2012, when latest version of Psych was 1.2.2.
This version outputs some scalars prefixed by exclamation mark:

  • when scalar starts with percent sign: Psych.dump({ foo: '%bar' }) # => "---\n:foo: ! '%bar'\n"
  • ends with colon: Psych.dump({ foo: 'bar:' }) # => "---\n:foo: ! 'bar:'\n"
  • starts or ends with space: Psych.dump({ foo: ' ' }) # => "---\n:foo: ! ' '\n"

I think those are the rules of adding this mark by Psych.

But! Now current version (almost; I use 2.0.0) of Psych outputs previous examples without exclamation mark. So I think we can safely omit this mark. I done this in my Rails applications (I use version 4.0.10) and locales are just fine.

Please, tell me what do you think and correct me if I'm wrong.


@tjku I agree with you.

If you remove exclamation marks and send us a pull request, I will merge it.


@kuroda Ok, I've done it: #493


@kuroda I came to conclusion that I've done too many things in my last pull request, so I closed it. Now I create a new pull request #523 which do only one thing. I hope it's ok now.

Link to previous pull request and discussion: #493

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment