@@ -87,13 +87,17 @@ function verify_translations(array $baseLanguageDef, string $altLanguageName, ar
8787 return $ ok ;
8888}
8989
90+ function language_file_path (string $ path , string $ code ) : string {
91+ return $ path . "/ " . "$ code.ini " ;
92+ }
93+
9094/**
9195 * @return string[]|null
9296 * @phpstan-return array<string, string>|null
9397 */
94- function parse_language_file (string $ path , string $ code ) : ?array {
95- $ lang = parse_ini_file ( $ path . " / " . " $ code .ini " , false , INI_SCANNER_RAW );
96- if ($ lang === false ){
98+ function parse_language_file (string $ contents ) : ?array {
99+ $ lang = parse_ini_string ( $ contents , false , INI_SCANNER_RAW );
100+ if ($ lang === false || count ( $ lang ) === 0 ){
97101 return null ;
98102 }
99103 return $ lang ;
@@ -151,7 +155,12 @@ function verify_keys(array $pocketmine, array $mojang, array $knownBadKeys) : ar
151155 fwrite (STDERR , "Required arguments: path \n" );
152156 exit (1 );
153157}
154- $ eng = parse_language_file ($ argv [1 ], "eng " );
158+ $ rawEng = file_get_contents (language_file_path ($ argv [1 ], "eng " ));
159+ if ($ rawEng === false ){
160+ fwrite (STDERR , "Failed to read eng.ini \n" );
161+ exit (1 );
162+ }
163+ $ eng = parse_language_file ($ rawEng );
155164if ($ eng === null ){
156165 fwrite (STDERR , "Failed to parse eng.ini \n" );
157166 exit (1 );
@@ -196,10 +205,19 @@ function verify_keys(array $pocketmine, array $mojang, array $knownBadKeys) : ar
196205 */
197206foreach (new \RegexIterator (new \FilesystemIterator ($ argv [1 ], \FilesystemIterator::CURRENT_AS_PATHNAME ), "/([a-z]+)\.ini$/ " , \RegexIterator::GET_MATCH ) as $ match ){
198207 $ code = $ match [1 ];
199- if ($ code === "eng " ){
208+ $ path = language_file_path ($ argv [1 ], $ code );
209+ $ raw = file_get_contents ($ path );
210+ if ($ raw === false ){
211+ fwrite (STDERR , "Unable to read contents of $ path \n" );
212+ $ exit = 1 ;
200213 continue ;
201214 }
202- $ otherLang = parse_language_file ($ argv [1 ], $ code );
215+ if (str_starts_with ($ raw , "\xef\xbb\xbf" )){
216+ fwrite (STDERR , "Unexpected byte-order mark at the start of $ code.ini \n" );
217+ $ exit = 1 ;
218+ //we can still try to parse the file - this is more of a cosmetic check than a functional one
219+ }
220+ $ otherLang = parse_language_file ($ raw );
203221 if ($ otherLang === null ){
204222 fwrite (STDERR , "Error parsing $ code.ini \n" );
205223 $ exit = 1 ;
0 commit comments