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

Skip to content

Commit d040be7

Browse files
committed
[Yaml] Allow tabs before comments at the end of a line
In Yaml 1.2 spec white space is space or tab
1 parent 6316de5 commit d040be7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter
209209
$i += strlen($output);
210210

211211
// remove comments
212-
if (false !== $strpos = strpos($output, ' #')) {
213-
$output = rtrim(substr($output, 0, $strpos));
212+
if (preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) {
213+
$output = substr($output, 0, $match[0][1]);
214214
}
215215
} elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
216216
$output = $match[1];

src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ yaml: |
77
ex2: "foo # bar" # comment
88
ex3: 'foo # bar' # comment
99
ex4: foo # comment
10+
ex5: foo # comment with tab before
11+
ex6: foo#foo # comment here
12+
ex7: foo # ignore me # and me
1013
php: |
11-
array('ex1' => 'foo # bar', 'ex2' => 'foo # bar', 'ex3' => 'foo # bar', 'ex4' => 'foo')
14+
array('ex1' => 'foo # bar', 'ex2' => 'foo # bar', 'ex3' => 'foo # bar', 'ex4' => 'foo', 'ex5' => 'foo', 'ex6' => 'foo#foo', 'ex7' => 'foo')
1215
---
1316
test: Comments in the middle
1417
brief: >

0 commit comments

Comments
 (0)