Skip to content

Commit

Permalink
bug #21279 #20411 fix Yaml parsing for very long quoted strings (Rich…
Browse files Browse the repository at this point in the history
…ardBradley)

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
  • Loading branch information
xabbuh committed Jan 14, 2017
2 parents aebb659 + 51bca66 commit c18c93b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -21,7 +21,7 @@
*/
class Inline
{
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\']*(?:\'\'[^\']*)*)\')';
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+)"|\'([^\']*+(?:\'\'[^\']*+)*+)\')';

private static $exceptionOnInvalidType = false;
private static $objectSupport = false;
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Expand Up @@ -410,4 +410,14 @@ public function testNotSupportedMissingValue()
{
Inline::parse('{this, is not, supported}');
}

public function testVeryLongQuotedStrings()
{
$longStringWithQuotes = str_repeat("x\r\n\\\"x\"x", 1000);

$yamlString = Inline::dump(array('longStringWithQuotes' => $longStringWithQuotes));
$arrayFromYaml = Inline::parse($yamlString);

$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
}
}

0 comments on commit c18c93b

Please sign in to comment.