Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 6577ca1

Browse files
committed
Emit JSON errors from PHP Parser
The PHP parser had a bug here in that it presumed JSON encoding would succeed (and there are reasons it might not). This checks the return value of `json_encode` and emits a relevant error message if appropriate. Before this, a triggering case would result in empty output and an unhelpful error message from `JSON.parse` upstream in the Ruby code.
1 parent 7b5a477 commit 6577ca1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

‎vendor/php-parser/parser.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@
1313

1414
$serializer = new PhpParser\Serializer\JSON;
1515
$nodes = $serializer->serialize($stmts);
16-
echo json_encode($nodes);
17-
16+
$json = json_encode($nodes);
17+
if (false === $json) {
18+
fwrite(STDERR, "Parse Error: JSON encoding failed: ".json_last_error_msg()."\n");
19+
exit(1);
20+
} else {
21+
echo $json;
22+
}
1823
} catch (PHPParser\Error $e) {
1924
fwrite(STDERR, "Parse Error: ".$e->getMessage()."\n");
2025
exit(1);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /