Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Yaml] Allow tabs before comments at the end of a line #15793

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 1 commit into from
Oct 7, 2015

Conversation

superdav42
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT

If a yml file has a tab character before a line ending comment the comment will be included in the parsed value. Yaml spec allows tab or space as whitespace characters so we need to check for tab as well. See included test.
Recently caused an odd and hard to find bug in our project.

See spec:
http://www.yaml.org/spec/1.2/spec.html#s-b-comment
http://www.yaml.org/spec/1.2/spec.html#s-separate-in-line
http://www.yaml.org/spec/1.2/spec.html#s-white

This is a new PR replacing #15747

@fabpot

@@ -209,7 +209,7 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter
$i += strlen($output);

// remove comments
if (false !== $strpos = strpos($output, ' #')) {
if ((false !== $strpos = strpos($output, '#')) && (' ' === $output[$strpos - 1] || "\t" === $output[$strpos - 1])) {
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't this break in case # is the first char is $output ?

Copy link
Member

Choose a reason for hiding this comment

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

and this would look for the wrong char in this case:

foo: test#foo # comment here

@stof
Copy link
Member

stof commented Sep 14, 2015

the current implementation is buggy.

status: needs work

@superdav42
Copy link
Contributor Author

@stof New revision should work in all cases. Also added test case mentioned to tests.

@@ -209,7 +209,7 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter
$i += strlen($output);

// remove comments
if (false !== $strpos = strpos($output, ' #')) {
if ((false !== $strpos = strpos($output, ' #')) || (false !== $strpos = strpos($output, "\t#"))) {
Copy link
Member

Choose a reason for hiding this comment

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

What if there is a mix of tabs and spaces?

Copy link
Member

Choose a reason for hiding this comment

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

the case being broke is when you have \t# #, where it would use the second one. We need to check for both positions and use the smaller one.

@fabpot
Copy link
Member

fabpot commented Sep 26, 2015

@superdav42 Any news?

In Yaml 1.2 spec white space is space or tab
@superdav42 superdav42 force-pushed the YamlCommentsAfterTab branch from 4fb5c12 to d040be7 Compare October 7, 2015 02:53
@superdav42
Copy link
Contributor Author

@fabpot Updated to use preg_match, now works for all test cases.
At first I thought I'd avoid the overhead of regexes turns out they are simpler and faster.

@fabpot
Copy link
Member

fabpot commented Oct 7, 2015

Thank you @superdav42.

@fabpot fabpot merged commit d040be7 into symfony:2.3 Oct 7, 2015
fabpot added a commit that referenced this pull request Oct 7, 2015
…perdav42)

This PR was merged into the 2.3 branch.

Discussion
----------

[Yaml] Allow tabs before comments at the end of a line

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT

If a yml file has a tab character before a line ending comment the comment will be included in the parsed value. Yaml spec allows tab or space as whitespace characters so we need to check for tab as well. See included test.
Recently caused an odd and hard to find bug in our project.

See spec:
http://www.yaml.org/spec/1.2/spec.html#s-b-comment
http://www.yaml.org/spec/1.2/spec.html#s-separate-in-line
http://www.yaml.org/spec/1.2/spec.html#s-white

This is a new PR replacing #15747

@fabpot

Commits
-------

d040be7 [Yaml] Allow tabs before comments at the end of a line
This was referenced Oct 27, 2015
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.

4 participants