File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,10 @@ public function setInput($input)
140140 */
141141 public function showPosition ()
142142 {
143+ if ($ this ->yylineno === 0 && $ this ->offset === 1 && $ this ->match !== '{ ' ) {
144+ return $ this ->match .'... ' . "\n^ " ;
145+ }
146+
143147 $ pre = str_replace ("\n" , '' , $ this ->getPastInput ());
144148 $ c = str_repeat ('- ' , max (0 , \strlen ($ pre ) - 1 )); // new Array(pre.length + 1).join("-");
145149
Original file line number Diff line number Diff line change @@ -177,6 +177,17 @@ public function testErrorAtBeginning()
177177 }
178178 }
179179
180+ public function testAvoidLeakingInfoForInvalidFiles ()
181+ {
182+ $ parser = new JsonParser ();
183+ try {
184+ $ parser ->parse ('ABCD ' );
185+ $ this ->fail ('Empty string should be invalid ' );
186+ } catch (ParsingException $ e ) {
187+ $ this ->assertContains ("Parse error on line 1: \nA... \n^ " , $ e ->getMessage ());
188+ }
189+ }
190+
180191 public function testParsesMultiInARow ()
181192 {
182193 $ parser = new JsonParser ();
You can’t perform that action at this time.
0 commit comments