8000 merged branch paul-matthews/master (PR #4042) · MattKetmo/symfony@37678e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37678e1

Browse files
committed
merged branch paul-matthews/master (PR symfony#4042)
Commits ------- 478227d Fixed quoting issues with Yaml Inline Parser Discussion ---------- [Yaml] fix parsing quotes problem Added some basic checking for quotes on their own within strings. Used single quote ' followed by "," and ":" to denote the end of the current string to test. Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: symfony#4021 Todo: N/A --------------------------------------------------------------------------- by fabpot at 2012-05-07T09:22:56Z After doing the requested changes, can you squash your commits? Thanks. --------------------------------------------------------------------------- by paul-matthews at 2012-05-09T13:29:45Z Resolved and squashed --------------------------------------------------------------------------- by travisbot at 2012-05-09T13:30:30Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1285048) (merged 5ce6d4e1 into 6c71409). --------------------------------------------------------------------------- by travisbot at 2012-05-09T13:31:06Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1285057) (merged 3592fcec into e54f4e4). --------------------------------------------------------------------------- by travisbot at 2012-05-09T13:33:40Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1285094) (merged e209f786 into e54f4e4). --------------------------------------------------------------------------- by travisbot at 2012-05-09T13:37:42Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1285153) (merged 0967b513 into e54f4e4). --------------------------------------------------------------------------- by fabpot at 2012-05-09T14:00:29Z It looks like that another commit is in your PR that should not be there. --------------------------------------------------------------------------- by paul-matthews at 2012-05-09T15:52:35Z Right-o will remove --------------------------------------------------------------------------- by paul-matthews at 2012-05-09T15:54:15Z resolved --------------------------------------------------------------------------- by travisbot at 2012-05-09T15:57:15Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1286339) (merged fc276209 into e66a0bb). --------------------------------------------------------------------------- by fabpot at 2012-05-10T05:20:18Z Apparently, some tests do not pass anymore after the patch. Can you have a look at them? Thanks. --------------------------------------------------------------------------- by paul-matthews at 2012-05-10T11:20:45Z Sure - looking into it. --------------------------------------------------------------------------- by paul-matthews at 2012-05-10T17:55:53Z I believe that's fixed. The entire suite works locally now. --------------------------------------------------------------------------- by travisbot at 2012-05-10T17:55:54Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1297641) (merged 884c02ed into fae4523). --------------------------------------------------------------------------- by paul-matthews at 2012-05-10T17:57:03Z Unsure why travis fails. --------------------------------------------------------------------------- by travisbot at 2012-05-10T18:00:28Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1297650) (merged 478227d into fae4523). --------------------------------------------------------------------------- by stof at 2012-06-09T13:24:52Z @fabpot 👍
2 parents 3bb7dc0 + 478227d commit 37678e1

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
class Inline
2222
{
2323
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\']*(?:\'\'[^\']*)*)\')';
24+
const REGEX_SINGLE_QUOTED_STRING = '(?:\'([^\']*(?:\'\'[^\']*)*)\')(?!.*\')';
25+
const REGEX_DOUBLE_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)")(?!.*")';
2426

2527
/**
2628
* Converts a YAML string to a PHP array.
@@ -196,7 +198,16 @@ static public function parseScalar($scalar, $delimiters = null, $stringDelimiter
196198
*/
197199
static private function parseQuotedScalar($scalar, &$i)
198200
{
199-
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
201+
// Only check the current item we're dealing with (for sequences)
202+
$subject = substr($scalar, $i);
203+
$items = preg_split('/[\'"]\s*(?:[,:]|[}\]]\s*,)/', $subject);
204+
$subject = substr($subject, 0, strlen($items[0]) + 1);
205+
206+
if (($scalar[$i] == "'"
207+
&& !preg_match('/'.self::REGEX_SINGLE_QUOTED_STRING.'/Au', $subject, $match))
208+
|| ($scalar[$i] == '"'
209+
&& !preg_match('/'.self::REGEX_DOUBLE_QUOTED_STRING.'/Au', $subject, $match))
210+
) {
200211
throw new ParseException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
201212
}
202213

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@ public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedTo
6565
$this->assertSame($value, Inline::parse(Inline::dump($value)));
6666
}
6767

68+
/**
69+
*
70+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
71+
*/
72+
public function testParseScalarWithIncorrectlyQuotedStringShouldThrowException()
73+
{
74+
$value = "'don't do somthin' like that'";
75+
Inline::parseScalar($value);
76+
}
77+
78+
/**
79+
*
80+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
81+
*/
82+
public function testParseScalarWithIncorrectlyDoubleQuotedStringShouldThrowException()
83+
{
84+
$value = '"don"t do somthin" like that"';
85+
Inline::parseScalar($value);
86+
}
87+
88+
public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
89+
{
90+
$value = "'don''t do somthin'' like that'";
91+
$expect = "don't do somthin' like that";
92+
93+
$this->assertSame($expect, Inline::parseScalar($value));
94+
}
95+
6896
protected function getTestsForParse()
6997
{
7098
return array(
@@ -124,6 +152,7 @@ protected function getTestsForParse()
124152
'[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))),
125153

126154
'[foo, bar: { foo: bar }]' => array('foo', '1' => array('bar' => array('foo' => 'bar'))),
155+
'[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']' => array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%',), true, '@service_container',),
127156
);
128157
}
129158

@@ -167,6 +196,8 @@ protected function getTestsForDump()
167196
'[foo, { bar: foo }]' => array('foo', array('bar' => 'foo')),
168197

169198
'[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))),
199+
200+
'[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']' => array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%',), true, '@service_container',),
170201
);
171202
}
172203
}

0 commit comments

Comments
 (0)
0