Переглянути джерело

Fix encoding of themes (#7565)

* Fix encoding of themes
Several HTML and URL encoding issues in the case of special chars in theme directory or in metadata.
Also usefull to simplify https://github.com/FreshRSS/FreshRSS/pull/7559

* Minor simplification

* Stricter decoding
Alexandre Alapetite 11 місяців тому
батько
коміт
25f57beb90
1 змінених файлів з 6 додано та 3 видалено
  1. 6 3
      app/Models/Themes.php

+ 6 - 3
app/Models/Themes.php

@@ -20,19 +20,21 @@ class FreshRSS_Themes extends Minz_Model {
 		$themes_list = self::getList();
 		$list = [];
 		foreach ($themes_list as $theme_dir) {
-			$theme = self::get_infos($theme_dir);
+			$theme_id = rawurlencode($theme_dir);
+			$theme = self::get_infos($theme_id);
 			if (is_array($theme) && trim($theme['name']) !== '') {
-				$list[$theme_dir] = $theme;
+				$list[$theme_id] = $theme;
 			}
 		}
 		return $list;
 	}
 
 	/**
+	 * @param string $theme_id is the rawurlencode'd theme directory name
 	 * @return false|array{id:string,name:string,author:string,description:string,version:float|string,files:array<string>,theme-color?:string|array{dark?:string,light?:string,default?:string}}
 	 */
 	public static function get_infos(string $theme_id): array|false {
-		$theme_dir = PUBLIC_PATH . self::$themesUrl . $theme_id;
+		$theme_dir = PUBLIC_PATH . self::$themesUrl . rawurldecode($theme_id);
 		if (is_dir($theme_dir)) {
 			$json_filename = $theme_dir . '/metadata.json';
 			if (file_exists($json_filename)) {
@@ -55,6 +57,7 @@ class FreshRSS_Themes extends Minz_Model {
 							'default' => is_string($res['theme-color']['default'] ?? null) ? $res['theme-color']['default'] : '',
 						];
 					}
+					$result = Minz_Helper::htmlspecialchars_utf8($result);
 					return $result;
 				}
 			}