-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
@@ -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])) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
the current implementation is buggy. status: needs work |
e27f69d
to
4fb5c12
Compare
@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#"))) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@superdav42 Any news? |
In Yaml 1.2 spec white space is space or tab
4fb5c12
to
d040be7
Compare
@fabpot Updated to use preg_match, now works for all test cases. |
Thank you @superdav42. |
…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
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