Skip to content

Documented the characters that provoke a YAML escaping string #4650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 3, 2015

Conversation

javiereguiluz
Copy link
Member

Q A
Doc fix? no
New docs? yes
Applies to all
Fixed tickets #4197

``,`` ``&`` ``*`` ``#`` ``?``
``|`` ``-`` ``<`` ``>`` ``=``
``!`` ``%`` ``@`` ``\```
===== ===== ===== ===== =====
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this table (and sphinx doesn't like it that there is an empty cell). It's a list, not a table imo. So either use an inline list: ":, {, }, [, ], ,, ... and \" or a multiline list

@wouterj
Copy link
Member

wouterj commented Dec 14, 2014

Thanks, @javiereguiluz ! I've always wondered about the exact rules, as the Yaml specs are not very clear :)

The diff was hard to read, but I tried to make sense of it and review it nonetheless. I may have commented on a wrong diff.

@javiereguiluz
Copy link
Member Author

@wouterj thanks for the detailed review! I've added everything you said.

'A single quote '' inside a single-quoted string'

If the string contains any of the following characters, it must be escaped with
single quotes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the times, using double quotes does the same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I really understand that. I read some parts of the specs when fixing some issues in the component. But I'm really far from understanding them in depth though.

Hopefully, @stof can have a look at this pull request and provide some feedback. Please. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more precise in the things that I remember: You can safely use double quotes when the string contains :, {, }, [, ], ,, #, -, % and @.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, you can use double quotes all the time if you want. But it makes the escaping harder, because you need to escape \ in it (because of control sequences) instead of just escaping single quotes

@javiereguiluz
Copy link
Member Author

I've added all the comments that you made. I think explanations are now much better. If you agree, let's merge and close some issues :)

@stof
Copy link
Member

stof commented Dec 16, 2014

There are a few other cases where using quotes is necessary. This is when the unquoted value would be parsed as another type than a string:

  • when the string is true or false (which would be parsed as a boolean)
  • when the string is null or ~ (which would be parsed as null)
  • when the string looks like an integer
  • when the string looks like a float (which includes 12e7 in YAML too)
  • when the string looks like a date (YAML defines a concept of timestamps, which are parsed to an integer being the Unix timestamp, even though I requested a long time ago to be able to parse it to a DateTime instead to handle it better)

@javiereguiluz
Copy link
Member Author

@stof thanks for your list of cases where we should enclose strings with quotes. I've just updated the docs.

@stof
Copy link
Member

stof commented Dec 16, 2014

👍

'A single quote '' inside a single-quoted string'

Strings containing any of the following characters must be quoted. Although you
can use double quotes, for these characters is more convenient to use single
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] characters it is more convenient [...]

* ``!``
* ``%``
* ``@``
* ``\```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use a single line list here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's confusing to put all these chars in a single line and separate them with a comma. You never know if the comma is a comma or a special char or part of other special char. That's why I used a table originally ;) In any case, tables, single-item lists or multiple-items lists all look awful to me in this case. I can't think of anything that makes this look OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think if you wrap every item as a literal using "``" and seperate them with a comma its much more readable

@weaverryan
Copy link
Member

WOW :)

@weaverryan weaverryan merged commit 2824867 into symfony:2.3 Jan 3, 2015
weaverryan added a commit that referenced this pull request Jan 3, 2015
…string (javiereguiluz)

This PR was merged into the 2.3 branch.

Discussion
----------

Documented the characters that provoke a YAML escaping string

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes
| Applies to    | all
| Fixed tickets | #4197

Commits
-------

2824867 Rewroded some contents and fixed some lists of elements
3a40d5a MAde some tweaks suggested by Wouter
044e88b Fixed a minor typo
63ea659 Added a lot more cases for enclosing strings with quotes
ce6e3eb Reworded some explanations to make them more clear
caaa272 Addressed all the comments made by Wouter
d5be25e Documented the characters that provoke a YAML escaping string
@javiereguiluz javiereguiluz deleted the document_yaml_escaped_chars branch February 18, 2015 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants