Skip to content

Commit e9a36be

Browse files
Merge branch '3.6' into 4.2
2 parents b56a067 + 04e416a commit e9a36be

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

src/Loader/Parser.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,23 @@ private static function parseValue($value)
114114
return Value::blank();
115115
}
116116

117-
return array_reduce(str_split($value), function ($data, $char) use ($value) {
117+
$result = array_reduce(str_split($value), function ($data, $char) use ($value) {
118118
return self::processChar($data[1], $char)->mapError(function ($err) use ($value) {
119119
throw new InvalidFileException(
120120
self::getErrorMessage($err, $value)
121121
);
122122
})->mapSuccess(function ($val) use ($data) {
123123
return [$data[0]->append($val[0], $val[1]), $val[2]];
124124
})->getSuccess();
125-
}, [Value::blank(), self::INITIAL_STATE])[0];
125+
}, [Value::blank(), self::INITIAL_STATE]);
126+
127+
if (in_array($result[1], [self::SINGLE_QUOTED_STATE, self::DOUBLE_QUOTED_STATE, self::ESCAPE_SEQUENCE_STATE], true)) {
128+
throw new InvalidFileException(
129+
self::getErrorMessage('a missing closing quote', $value)
130+
);
131+
}
132+
133+
return $result[0];
126134
}
127135

128136
/**

tests/Dotenv/LinesTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,17 @@ public function testProcessClosingSlash()
5353

5454
self::assertSame($expected, $lines);
5555
}
56+
57+
public function testProcessBadQuotes()
58+
{
59+
$lines = [
60+
"TEST=\"erert\nTEST='erert\n",
61+
];
62+
63+
$expected = [
64+
"TEST=\"erert\nTEST='erert\n",
65+
];
66+
67+
self::assertSame($expected, $lines);
68+
}
5669
}

tests/Dotenv/ParserTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,40 @@ public function testParserEscapingSingle()
226226
self::assertSame('iiiiviiiixiiiiviiii\\a', $output[1]->getChars());
227227
self::assertSame([], $output[1]->getVars());
228228
}
229+
230+
/**
231+
* @expectedException \Dotenv\Exception\InvalidFileException
232+
* @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ['erert].
233+
*/
234+
public function testMissingClosingSingleQuote()
235+
{
236+
Parser::parse('TEST=\'erert');
237+
}
238+
239+
/**
240+
* @expectedException \Dotenv\Exception\InvalidFileException
241+
* @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["erert].
242+
*/
243+
public function testMissingClosingDoubleQuote()
244+
{
245+
Parser::parse('TEST="erert');
246+
}
247+
248+
/**
249+
* @expectedException \Dotenv\Exception\InvalidFileException
250+
* @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["erert].
251+
*/
252+
public function testMissingClosingQuotes()
253+
{
254+
Parser::parse("TEST=\"erert\nTEST='erert\n");
255+
}
256+
257+
/**
258+
* @expectedException \Dotenv\Exception\InvalidFileException
259+
* @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["\].
260+
*/
261+
public function testMissingClosingQuoteWithEscape()
262+
{
263+
Parser::parse('TEST="\\');
264+
}
229265
}

0 commit comments

Comments
 (0)