Просмотр исходного кода

i18n CLI improve parsing (#4197)

https://github.com/FreshRSS/FreshRSS/pull/3932#discussion_r800043744
Alexandre Alapetite 4 лет назад
Родитель
Сommit
e28a2e320e
1 измененных файлов с 12 добавлено и 4 удалено
  1. 12 4
      cli/i18n/I18nFile.php

+ 12 - 4
cli/i18n/I18nFile.php

@@ -54,16 +54,24 @@ class I18nFile {
 		$content = str_replace('<?php', '', $content);
 
 		$content = preg_replace([
-			"#',\s*//\s*TODO#i",
-			"#',\s*//\s*DIRTY#i",
-			"#',\s*//\s*IGNORE#i",
+			"#',\s*//\s*TODO.*#i",
+			"#',\s*//\s*DIRTY.*#i",
+			"#',\s*//\s*IGNORE.*#i",
 		], [
 			' -> todo\',',
 			' -> dirty\',',
 			' -> ignore\',',
 		], $content);
 
-		$content = eval($content);
+		try {
+			$content = eval($content);
+		} catch (ParseError $ex) {
+			if (defined('STDERR')) {
+				fwrite(STDERR, "Error while processing: $filename\n");
+				fwrite(STDERR, $ex);
+			}
+			die(1);
+		}
 
 		if (is_array($content)) {
 			return $content;