소스 검색

Detect and report UTF8 encoding errors in json files

Jordi Boggiano 13 년 전
부모
커밋
3bdee3aabe
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 2
      src/Composer/Json/JsonFile.php

+ 5 - 2
src/Composer/Json/JsonFile.php

@@ -271,7 +271,7 @@ class JsonFile
     public static function parseJson($json)
     {
         $data = json_decode($json, true);
-        if (null === $data && 'null' !== $json) {
+        if (null === $data && json_last_error()) {
             self::validateSyntax($json);
         }
 
@@ -289,8 +289,11 @@ class JsonFile
     {
         $parser = new JsonParser();
         $result = $parser->lint($json);
-
         if (null === $result) {
+            if (defined('JSON_ERROR_UTF8') && json_last_error() === JSON_ERROR_UTF8) {
+                throw new \UnexpectedValueException('JSON file is not UTF-8 encoded');
+            }
+
             return true;
         }