Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Exclamation marks in YAML #334

Open
andyw8 opened this Issue · 10 comments

5 participants

@andyw8

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

formats:
      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.

@andyw8

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.

@tigrish
@andyw8

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

@andyw8

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.

@digitalfrost

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"

@tjku

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.

@kuroda
Collaborator

@tjku I agree with you.

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

@tjku

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

@meismann meismann referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@meismann meismann referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@meismann meismann referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@meismann meismann referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@meismann meismann referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@tjku

@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
Something went wrong with that request. Please try again.