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)
106106 return $ value ;
107107 }
108108
109- return array_reduce (str_split ($ value ), function ($ data , $ char ) use ($ value ) {
109+ $ result = array_reduce (str_split ($ value ), function ($ data , $ char ) use ($ value ) {
110110 switch ($ data [1 ]) {
111111 case self ::INITIAL_STATE :
112112 if ($ char === '" ' || $ char === '\'' ) {
@@ -155,7 +155,15 @@ private static function parseValue($value)
155155 case self ::COMMENT_STATE :
156156 return [$ data [0 ], self ::COMMENT_STATE ];
157157 }
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 ];
159167 }
160168
161169 /**
Original file line number Diff line number Diff line change @@ -51,4 +51,17 @@ public function testProcessClosingSlash()
5151
5252 $ this ->assertSame ($ expected , $ lines );
5353 }
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+ }
5467}
Original file line number Diff line number Diff line change @@ -106,4 +106,40 @@ public function testParserEscapingSingle()
106106 {
107107 Parser::parse ('FOO_BAD= \'iiiiviiiixiiiiviiii \\a \'' );
108108 }
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+ }
109145}
You can’t perform that action at this time.
0 commit comments