"mediawiki/mediawiki-codesniffer": "20.0.0",
"monolog/monolog": "~1.22.1",
"nikic/php-parser": "3.1.3",
+ "seld/jsonlint": "1.7.1",
"nmred/kafka-php": "0.1.5",
"phpunit/phpunit": "4.8.36 || ^6.5",
"psy/psysh": "0.9.6",
use Composer\Spdx\SpdxLicenses;
use JsonSchema\Validator;
+use Seld\JsonLint\JsonParser;
+use Seld\JsonLint\ParsingException;
/**
* @since 1.29
'The spdx-licenses library cannot be found, please install it through composer.'
);
return false;
+ } elseif ( !class_exists( JsonParser::class ) ) {
+ call_user_func( $this->missingDepCallback,
+ 'The JSON lint library cannot be found, please install it through composer.'
+ );
}
return true;
* @throws ExtensionJsonValidationError on any failure
*/
public function validate( $path ) {
- $data = json_decode( file_get_contents( $path ) );
- if ( !is_object( $data ) ) {
+ $contents = file_get_contents( $path );
+ $jsonParser = new JsonParser();
+ try {
+ $data = $jsonParser->parse( $contents, JsonParser::DETECT_KEY_CONFLICTS );
+ } catch ( ParsingException $e ) {
+ if ( $e instanceof \Seld\JsonLint\DuplicateKeyException ) {
+ throw new ExtensionJsonValidationError( $e->getMessage() );
+ }
throw new ExtensionJsonValidationError( "$path is not valid JSON" );
}