Skip to content

Commit 6796885

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: make fabbot happy Fix issue 40507: Tabs as separators between tokens [Cache] phpredis: Added full TLS support for RedisCluster
2 parents 5cdc184 + e1515d3 commit 6796885

File tree

2 files changed

+63
-22
lines changed

2 files changed

+63
-22
lines changed

Parser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private function doParse(string $value, int $flags)
212212
array_pop($this->refsBeingParsed);
213213
}
214214
} elseif (
215-
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:( ++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
215+
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
216216
&& (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
217217
) {
218218
if ($context && 'sequence' == $context) {
@@ -230,7 +230,7 @@ private function doParse(string $value, int $flags)
230230
}
231231

232232
if (!\is_string($key) && !\is_int($key)) {
233-
throw new ParseException(sprintf('%s keys are not supported. Quote your evaluable mapping keys instead.', is_numeric($key) ? 'Numeric' : 'Non-string'), $this->getRealCurrentLineNb() + 1, $this->currentLine);
233+
throw new ParseException((is_numeric($key) ? 'Numeric' : 'Non-string').' keys are not supported. Quote your evaluable mapping keys instead.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
234234
}
235235

236236
// Convert float keys to strings, to avoid being converted to integers by PHP
@@ -245,7 +245,7 @@ private function doParse(string $value, int $flags)
245245
$refName = substr(rtrim($values['value']), 1);
246246
if (!\array_key_exists($refName, $this->refs)) {
247247
if (false !== $pos = array_search($refName, $this->refsBeingParsed, true)) {
248-
throw new ParseException(sprintf('Circular reference [%s, %s] detected for reference "%s".', implode(', ', \array_slice($this->refsBeingParsed, $pos)), $refName, $refName), $this->currentLineNb + 1, $this->currentLine, $this->filename);
248+
throw new ParseException(sprintf('Circular reference [%s] detected for reference "%s".', implode(', ', array_merge(\array_slice($this->refsBeingParsed, $pos), [$refName])), $refName), $this->currentLineNb + 1, $this->currentLine, $this->filename);
249249
}
250250

251251
throw new ParseException(sprintf('Reference "%s" does not exist.', $refName), $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
@@ -732,7 +732,7 @@ private function parseValue(string $value, int $flags, string $context)
732732

733733
if (!\array_key_exists($value, $this->refs)) {
734734
if (false !== $pos = array_search($value, $this->refsBeingParsed, true)) {
735-
throw new ParseException(sprintf('Circular reference [%s, %s] detected for reference "%s".', implode(', ', \array_slice($this->refsBeingParsed, $pos)), $value, $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
735+
throw new ParseException(sprintf('Circular reference [%s] detected for reference "%s".', implode(', ', array_merge(\array_slice($this->refsBeingParsed, $pos), [$value])), $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
736736
}
737737

738738
throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
@@ -1225,7 +1225,7 @@ private function lexInlineQuotedString(int &$cursor = 0): string
12251225
}
12261226
} while ($this->moveToNextLine());
12271227

1228-
throw new ParseException('Malformed inline YAML string');
1228+
throw new ParseException('Malformed inline YAML string.');
12291229
}
12301230

12311231
private function lexUnquotedString(int &$cursor): string
@@ -1296,7 +1296,7 @@ private function lexInlineStructure(int &$cursor, string $closingTag): string
12961296
}
12971297
} while ($this->moveToNextLine());
12981298

1299-
throw new ParseException('Malformed inline YAML string');
1299+
throw new ParseException('Malformed inline YAML string.');
13001300
}
13011301

13021302
private function consumeWhitespaces(int &$cursor): bool

Tests/ParserTest.php

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,67 @@ public function getNonStringMappingKeysData()
5252
return $this->loadTestsFromFixtureFiles('nonStringKeys.yml');
5353
}
5454

55-
public function testTabsInYaml()
55+
/**
56+
* @dataProvider invalidIndentation
57+
*/
58+
public function testTabsAsIndentationInYaml(string $given, string $expectedMessage)
5659
{
57-
// test tabs in YAML
58-
$yamls = [
59-
"foo:\n bar",
60-
"foo:\n bar",
61-
"foo:\n bar",
62-
"foo:\n bar",
60+
$this->expectException(ParseException::class);
61+
$this->expectExceptionMessage($expectedMessage);
62+
$this->parser->parse($given);
63+
}
64+
65+
public function invalidIndentation(): array
66+
{
67+
return [
68+
[
69+
"foo:\n\tbar",
70+
"A YAML file cannot contain tabs as indentation at line 2 (near \"\tbar\").",
71+
],
72+
[
73+
"foo:\n \tbar",
74+
"A YAML file cannot contain tabs as indentation at line 2 (near \"\tbar\").",
75+
],
76+
[
77+
"foo:\n\t bar",
78+
"A YAML file cannot contain tabs as indentation at line 2 (near \"\t bar\").",
79+
],
80+
[
81+
"foo:\n \t bar",
82+
"A YAML file cannot contain tabs as indentation at line 2 (near \"\t bar\").",
83+
],
6384
];
85+
}
6486

65-
foreach ($yamls as $yaml) {
66-
try {
67-
$this->parser->parse($yaml);
87+
/**
88+
* @dataProvider validTokenSeparators
89+
*/
90+
public function testValidTokenSeparation(string $given, array $expected)
91+
{
92+
$actual = $this->parser->parse($given);
93+
$this->assertEquals($expected, $actual);
94+
}
6895

69-
$this->fail('YAML files must not contain tabs');
70-
} catch (\Exception $e) {
71-
$this->assertInstanceOf(\Exception::class, $e, 'YAML files must not contain tabs');
72-
$this->assertEquals('A YAML file cannot contain tabs as indentation at line 2 (near "'.strpbrk($yaml, "\t").'").', $e->getMessage(), 'YAML files must not contain tabs');
73-
}
74-
}
96+
public function validTokenSeparators(): array
97+
{
98+
return [
99+
[
100+
'foo: bar',
101+
['foo' => 'bar'],
102+
],
103+
[
104+
"foo:\tbar",
105+
['foo' => 'bar'],
106+
],
107+
[
108+
"foo: \tbar",
109+
['foo' => 'bar'],
110+
],
111+
[
112+
"foo:\t bar",
113+
['foo' => 'bar'],
114+
],
115+
];
75116
}
76117

77118
public function testEndOfTheDocumentMarker()

0 commit comments

Comments
 (0)