Skip to content

Commit c18c93b

Browse files
committed
bug #21279 #20411 fix Yaml parsing for very long quoted strings (RichardBradley)
This PR was merged into the 2.7 branch. Discussion ---------- #20411 fix Yaml parsing for very long quoted strings | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20411 | License | MIT | Doc PR | no This fixes #20411, a YAML string with too many backslash escapes can trigger a `PREG_BACKTRACK_LIMIT_ERROR` error in the Yaml parser. There should be no behavioural change other than the bug fix I have included a test which fails before this fix and passes after this fix. Commits ------- 51bca66 #20411 fix Yaml parsing for very long quoted strings
2 parents aebb659 + 51bca66 commit c18c93b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Symfony/Component/Yaml/Inline.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class Inline
2323
{
24-
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\']*(?:\'\'[^\']*)*)\')';
24+
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+)"|\'([^\']*+(?:\'\'[^\']*+)*+)\')';
2525

2626
private static $exceptionOnInvalidType = false;
2727
private static $objectSupport = false;

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

+10
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,14 @@ public function testNotSupportedMissingValue()
410410
{
411411
Inline::parse('{this, is not, supported}');
412412
}
413+
414+
public function testVeryLongQuotedStrings()
415+
{
416+
$longStringWithQuotes = str_repeat("x\r\n\\\"x\"x", 1000);
417+
418+
$yamlString = Inline::dump(array('longStringWithQuotes' => $longStringWithQuotes));
419+
$arrayFromYaml = Inline::parse($yamlString);
420+
421+
$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
422+
}
413423
}

0 commit comments

Comments
 (0)