From 8c18de5a41a960fbced81964d0e4cda119411658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dezs=C5=91=20BICZ=C3=93?= Date: Tue, 6 Jun 2023 21:27:55 +0000 Subject: [PATCH] Handle better nullable file parameter (#11486) * Handle better nullable file parameter Closes #11483 * CS fix --- src/Composer/Json/JsonFile.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index d4f851f8a..3ad34a619 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -338,12 +338,22 @@ class JsonFile $result = $parser->lint($json); if (null === $result) { if (defined('JSON_ERROR_UTF8') && JSON_ERROR_UTF8 === json_last_error()) { - throw new \UnexpectedValueException('"'.$file.'" is not UTF-8, could not parse as JSON'); + if ($file === null) { + throw new \UnexpectedValueException('The input is not UTF-8, could not parse as JSON'); + } else { + throw new \UnexpectedValueException('"' . $file . '" is not UTF-8, could not parse as JSON'); + } } return true; } - throw new ParsingException('"'.$file.'" does not contain valid JSON'."\n".$result->getMessage(), $result->getDetails()); + if ($file === null) { + throw new ParsingException('The input does not contain valid JSON' . "\n" . $result->getMessage(), + $result->getDetails()); + } else { + throw new ParsingException('"' . $file . '" does not contain valid JSON' . "\n" . $result->getMessage(), + $result->getDetails()); + } } }