File tree Expand file tree Collapse file tree 3 files changed +59
-2
lines changed Expand file tree Collapse file tree 3 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ private static function parseValue($value)
106
106
return $ value ;
107
107
}
108
108
109
- return array_reduce (str_split ($ value ), function ($ data , $ char ) use ($ value ) {
109
+ $ result = array_reduce (str_split ($ value ), function ($ data , $ char ) use ($ value ) {
110
110
switch ($ data [1 ]) {
111
111
case self ::INITIAL_STATE :
112
112
if ($ char === '" ' || $ char === '\'' ) {
@@ -155,7 +155,15 @@ private static function parseValue($value)
155
155
case self ::COMMENT_STATE :
156
156
return [$ data [0 ], self ::COMMENT_STATE ];
157
157
}
158
- }, ['' , self ::INITIAL_STATE ])[0 ];
158
+ }, ['' , self ::INITIAL_STATE ]);
159
+
160
+ if ($ result [1 ] === self ::QUOTED_STATE || $ result [1 ] === self ::ESCAPE_STATE ) {
161
+ throw new InvalidFileException (
162
+ self ::getErrorMessage ('a missing closing quote ' , $ value )
163
+ );
164
+ }
165
+
166
+ return $ result [0 ];
159
167
}
160
168
161
169
/**
Original file line number Diff line number Diff line change @@ -51,4 +51,17 @@ public function testProcessClosingSlash()
51
51
52
52
$ this ->assertSame ($ expected , $ lines );
53
53
}
54
+
55
+ public function testProcessBadQuotes ()
56
+ {
57
+ $ lines = [
58
+ "TEST= \"erert \nTEST='erert \n" ,
59
+ ];
60
+
61
+ $ expected = [
62
+ "TEST= \"erert \nTEST='erert \n" ,
63
+ ];
64
+
65
+ $ this ->assertSame ($ expected , $ lines );
66
+ }
54
67
}
Original file line number Diff line number Diff line change @@ -106,4 +106,40 @@ public function testParserEscapingSingle()
106
106
{
107
107
Parser::parse ('FOO_BAD= \'iiiiviiiixiiiiviiii \\a \'' );
108
108
}
109
+
110
+ /**
111
+ * @expectedException \Dotenv\Exception\InvalidFileException
112
+ * @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ['erert].
113
+ */
114
+ public function testMissingClosingSingleQuote ()
115
+ {
116
+ Parser::parse ('TEST= \'erert ' );
117
+ }
118
+
119
+ /**
120
+ * @expectedException \Dotenv\Exception\InvalidFileException
121
+ * @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["erert].
122
+ */
123
+ public function testMissingClosingDoubleQuote ()
124
+ {
125
+ Parser::parse ('TEST="erert ' );
126
+ }
127
+
128
+ /**
129
+ * @expectedException \Dotenv\Exception\InvalidFileException
130
+ * @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["erert].
131
+ */
132
+ public function testMissingClosingQuotes ()
133
+ {
134
+ Parser::parse ("TEST= \"erert \nTEST='erert \n" );
135
+ }
136
+
137
+ /**
138
+ * @expectedException \Dotenv\Exception\InvalidFileException
139
+ * @expectedExceptionMessage Failed to parse dotenv file due to a missing closing quote. Failed at ["\].
140
+ */
141
+ public function testMissingClosingQuoteWithEscape ()
142
+ {
143
+ Parser::parse ('TEST=" \\' );
144
+ }
109
145
}
You can’t perform that action at this time.
0 commit comments