Skip to content

Commit

Permalink
Merge branch '2.6' into 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Jan 20, 2021
2 parents e778c8b + 7417448 commit 04e416a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static function parseValue($value)
return $value;
}

return array_reduce(str_split($value), function ($data, $char) use ($value) {
$result = array_reduce(str_split($value), function ($data, $char) use ($value) {
switch ($data[1]) {
case self::INITIAL_STATE:
if ($char === '"' || $char === '\'') {
Expand Down Expand Up @@ -155,7 +155,15 @@ private static function parseValue($value)
case self::COMMENT_STATE:
return [$data[0], self::COMMENT_STATE];
}
}, ['', self::INITIAL_STATE])[0];
}, ['', self::INITIAL_STATE]);

if ($result[1] === self::QUOTED_STATE || $result[1] === self::ESCAPE_STATE) {
throw new InvalidFileException(
self::getErrorMessage('a missing closing quote', $value)
);
}

return $result[0];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/Dotenv/LinesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,17 @@ public function testProcessClosingSlash()

$this->assertSame($expected, $lines);
}

public function testProcessBadQuotes()
{
$lines = [
"TEST=\"erert\nTEST='erert\n",
];

$expected = [
"TEST=\"erert\nTEST='erert\n",
];

$this->assertSame($expected, $lines);
}
}
36 changes: 36 additions & 0 deletions tests/Dotenv/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,40 @@ public function testParserEscapingSingle()
{
Parser::parse('FOO_BAD=\'iiiiviiiixiiiiviiii\\a\'');
}

/**
* @expectedException \Dotenv\Exception\InvalidFileException
* @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ['erert].
*/
public function testMissingClosingSingleQuote()
{
Parser::parse('TEST=\'erert');
}

/**
* @expectedException \Dotenv\Exception\InvalidFileException
* @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["erert].
*/
public function testMissingClosingDoubleQuote()
{
Parser::parse('TEST="erert');
}

/**
* @expectedException \Dotenv\Exception\InvalidFileException
* @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["erert].
*/
public function testMissingClosingQuotes()
{
Parser::parse("TEST=\"erert\nTEST='erert\n");
}

/**
* @expectedException \Dotenv\Exception\InvalidFileException
* @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["\].
*/
public function testMissingClosingQuoteWithEscape()
{
Parser::parse('TEST="\\');
}
}

0 comments on commit 04e416a

Please sign in to comment.