Forráskód Böngészése

Safer handling of DB null content (#8319)

https://github.com/FreshRSS/FreshRSS/discussions/8314#discussioncomment-15261119
Alexandre Alapetite 3 hónapja
szülő
commit
493bb88535
1 módosított fájl, 6 hozzáadás és 6 törlés
  1. 6 6
      lib/lib_rss.php

+ 6 - 6
lib/lib_rss.php

@@ -150,16 +150,16 @@ function safe_ascii(?string $text): string {
 }
 
 if (function_exists('mb_convert_encoding')) {
-	function safe_utf8(string $text): string {
-		return mb_convert_encoding($text, 'UTF-8', 'UTF-8') ?: '';
+	function safe_utf8(?string $text): string {
+		return $text === null ? '' : (mb_convert_encoding($text, 'UTF-8', 'UTF-8') ?: '');
 	}
 } elseif (function_exists('iconv')) {
-	function safe_utf8(string $text): string {
-		return iconv('UTF-8', 'UTF-8//IGNORE', $text) ?: '';
+	function safe_utf8(?string $text): string {
+		return $text === null ? '' : (iconv('UTF-8', 'UTF-8//IGNORE', $text) ?: '');
 	}
 } else {
-	function safe_utf8(string $text): string {
-		return $text;
+	function safe_utf8(?string $text): string {
+		return $text ?? '';
 	}
 }