Merge branch '3.4' into 4.3
* 3.4: [Dotenv] allow LF in single-quoted strings [Yaml] Throw exception for tagged invalid inline elements
This commit is contained in:
commit
0b4c37a36c
@ -263,25 +263,18 @@ final class Dotenv
|
||||
|
||||
do {
|
||||
if ("'" === $this->data[$this->cursor]) {
|
||||
$value = '';
|
||||
++$this->cursor;
|
||||
$len = 0;
|
||||
|
||||
while ("\n" !== $this->data[$this->cursor]) {
|
||||
if ("'" === $this->data[$this->cursor]) {
|
||||
break;
|
||||
}
|
||||
$value .= $this->data[$this->cursor];
|
||||
++$this->cursor;
|
||||
do {
|
||||
if ($this->cursor + ++$len === $this->end) {
|
||||
$this->cursor += $len;
|
||||
|
||||
if ($this->cursor === $this->end) {
|
||||
throw $this->createFormatException('Missing quote to end the value');
|
||||
}
|
||||
}
|
||||
if ("\n" === $this->data[$this->cursor]) {
|
||||
throw $this->createFormatException('Missing quote to end the value');
|
||||
}
|
||||
++$this->cursor;
|
||||
$v .= $value;
|
||||
} while ("'" !== $this->data[$this->cursor + $len]);
|
||||
|
||||
$v .= substr($this->data, 1 + $this->cursor, $len - 1);
|
||||
$this->cursor += 1 + $len;
|
||||
} elseif ('"' === $this->data[$this->cursor]) {
|
||||
$value = '';
|
||||
++$this->cursor;
|
||||
|
@ -40,7 +40,7 @@ class DotenvTest extends TestCase
|
||||
['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
|
||||
['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"],
|
||||
['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"],
|
||||
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"],
|
||||
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 9"],
|
||||
['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"],
|
||||
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
|
||||
['FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"],
|
||||
@ -112,6 +112,7 @@ class DotenvTest extends TestCase
|
||||
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
|
||||
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
|
||||
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
|
||||
["FOO='bar\nfoo'", ['FOO' => "bar\nfoo"]],
|
||||
['FOO=" FOO "', ['FOO' => ' FOO ']],
|
||||
['FOO=" "', ['FOO' => ' ']],
|
||||
['PATH="c:\\\\"', ['PATH' => 'c:\\']],
|
||||
|
@ -94,15 +94,15 @@ class Inline
|
||||
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
|
||||
}
|
||||
|
||||
if (null !== $tag && '' !== $tag) {
|
||||
return new TaggedValue($tag, $result);
|
||||
}
|
||||
|
||||
// some comments are allowed at the end
|
||||
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
|
||||
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
|
||||
if (null !== $tag && '' !== $tag) {
|
||||
return new TaggedValue($tag, $result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
} finally {
|
||||
if (isset($mbEncoding)) {
|
||||
|
@ -167,6 +167,12 @@ class InlineTest extends TestCase
|
||||
Inline::parse('{ foo: bar } bar');
|
||||
}
|
||||
|
||||
public function testParseInvalidTaggedSequenceShouldThrowException()
|
||||
{
|
||||
$this->expectException('Symfony\Component\Yaml\Exception\ParseException');
|
||||
Inline::parse('!foo { bar: baz } qux', Yaml::PARSE_CUSTOM_TAGS);
|
||||
}
|
||||
|
||||
public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
|
||||
{
|
||||
$value = "'don''t do somthin'' like that'";
|
||||
|
Reference in New Issue
Block a user