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

Simplify pathInfo() (#9287)

Simplification of https://github.com/FreshRSS/FreshRSS/pull/9282
https://github.com/FreshRSS/FreshRSS/issues/9281#issuecomment-5618617227
Alexandre Alapetite 21 часов назад
Родитель
Сommit
d58459a84a
1 измененных файлов с 6 добавлено и 10 удалено
  1. 6 10
      lib/Minz/Request.php

+ 6 - 10
lib/Minz/Request.php

@@ -283,20 +283,16 @@ class Minz_Request {
 	}
 
 	/**
-	 * Returns `PATH_INFO` with `SCRIPT_NAME` stripped from the beginning of it,
-	 * if it's there on some shared hosting configurations.
+	 * Returns `PATH_INFO` accounting for a bug when sometimes it may contain `SCRIPT_NAME` value instead of blank
 	 */
 	public static function pathInfo(): string {
-		$pathInfo = $_SERVER['PATH_INFO'] ?? $_SERVER['ORIG_PATH_INFO'] ?? '';
+		$pathInfo = $_SERVER['PATH_INFO'] ?? $_SERVER['ORIG_PATH_INFO'] ?? null;
 		if (!is_string($pathInfo)) {
-			$pathInfo = '';
+			return '';
 		}
-		$scriptName = $_SERVER['SCRIPT_NAME'] ?? '';
-		if (!is_string($scriptName)) {
-			$scriptName = '';
-		}
-		if ($pathInfo !== '' && $scriptName !== '' && str_starts_with($pathInfo, $scriptName)) {
-			$pathInfo = substr($pathInfo, strlen($scriptName));
+		$scriptName = $_SERVER['SCRIPT_NAME'] ?? null;
+		if ($scriptName === $pathInfo) {
+			return '';
 		}
 		return $pathInfo;
 	}