8000 #20411 fix Yaml parsing for very long quoted strings · symfony/symfony@ec7f68e · GitHub
[go: up one dir, main page]

Skip to content

Commit ec7f68e

Browse files
#20411 fix Yaml parsing for very long quoted strings
1 parent 6e001c8 commit ec7f68e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 6 additions & 4 deletions
< 8000 td data-grid-cell-id="diff-0a12ae513347f5548e97b59d07e5648e5a83298e73a36e77e1ee9e597dbe3f5a-65-65-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">65
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct($offset = 0, $totalNumberOfLines = null, array $skip
6161
*/
6262
public function parse($value, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false)
6363
{
64-
if (!self::preg_match('//u', $value)) {
64+
if (false === preg_match('//u', $value)) {
65
throw new ParseException('The YAML value does not appear to be valid UTF-8.');
6666
}
6767
$this->currentLineNb = -1;
@@ -127,7 +127,6 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
127127
} elseif (self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
128128
&& (false === strpos($values['key'], ' #')
129129
|| in_array($values['key'][0], array('"', "'")))) {
130-
131130
if ($context && 'sequence' == $context) {
132131
throw new ParseException('You cannot define a mapping item when in a sequence', $this->currentLineNb + 1, $this->currentLine);
133132
}
@@ -269,7 +268,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
269268
return $value;
270269
}
271270

272-
throw new ParseException("Unable to parse", $this->getRealCurrentLineNb() + 1, $this->currentLine);
271+
throw new ParseException('Unable to parse', $this->getRealCurrentLineNb() + 1, $this->currentLine);
273272
}
274273
}
275274

@@ -794,9 +793,11 @@ private function isBlockScalarHeader()
794793
* in the YAML engine
795794
*
796795
* @throws ParseException on a PCRE internal error
796+
*
797797
* @see preg_last_error()
798+
* @internal
798799
*/
799-
static function preg_match($pattern, $subject, &$matches = null, $flags = 0, $offset = 0)
800+
public static function preg_match($pattern, $subject, &$matches = null, $flags = 0, $offset = 0)
800801
{
801802
$ret = preg_match($pattern, $subject, $matches, $flags, $offset);
802803
if ($ret === false) {
@@ -822,6 +823,7 @@ static function preg_match($pattern, $subject, &$matches = null, $flags = 0, $of
822823

823824
throw new ParseException($error);
824825
}
826+
825827
return $ret;
826828
}
827829
}

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@ public function parserThrowsExceptionWithCorrectLineNumberProvider()
11471147

11481148
public function testCanParseVeryLongValue()
11491149
{
1150-
$longStringWithSpaces = str_repeat("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ", 20000);
1151-
$trickyVal = array("x" => $longStringWithSpaces);
1150+
$longStringWithSpaces = str_repeat('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ', 20000);
1151+
$trickyVal = array('x' => $longStringWithSpaces);
11521152

11531153
$yamlString = Yaml::dump($trickyVal);
11541154
$arrayFromYaml = $this->parser->parse($yamlString);

0 commit comments

Comments
 (0)
0