浏览代码

Better trim base_url (#4423)

Avoid usual errors for instance with quotes, especially when provided through Docker / CLI
Alexandre Alapetite 3 年之前
父节点
当前提交
47ab9d5e77
共有 1 个文件被更改,包括 9 次插入28 次删除
  1. 9 28
      lib/Minz/Request.php

+ 9 - 28
lib/Minz/Request.php

@@ -133,10 +133,8 @@ class Minz_Request {
 
 	/**
 	 * Return true if the request is over HTTPS, false otherwise (HTTP)
-	 *
-	 * @return boolean
 	 */
-	public static function isHttps() {
+	public static function isHttps(): bool {
 		$header = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '';
 		if ('' != $header) {
 			return 'https' === strtolower($header);
@@ -159,10 +157,7 @@ class Minz_Request {
 		return filter_var("{$protocol}://{$host}{$port}{$prefix}{$path}", FILTER_SANITIZE_URL);
 	}
 
-	/**
-	 * @return string
-	 */
-	private static function extractProtocol() {
+	private static function extractProtocol(): string {
 		if (self::isHttps()) {
 			return 'https';
 		}
@@ -202,10 +197,7 @@ class Minz_Request {
 		return self::isHttps() ? 443 : 80;
 	}
 
-	/**
-	 * @return string
-	 */
-	private static function extractPortForUrl() {
+	private static function extractPortForUrl(): string {
 		if (self::isHttps() && 443 !== $port = self::extractPort()) {
 			return ":{$port}";
 		}
@@ -215,10 +207,7 @@ class Minz_Request {
 		return '';
 	}
 
-	/**
-	 * @return string
-	 */
-	private static function extractPrefix() {
+	private static function extractPrefix(): string {
 		if ('' != $prefix = ($_SERVER['HTTP_X_FORWARDED_PREFIX'] ?? '')) {
 			return rtrim($prefix, '/ ');
 		}
@@ -235,13 +224,11 @@ class Minz_Request {
 	}
 
 	/**
-	 * Return the base_url from configuration and add a suffix if given.
-	 *
-	 * @return string base_url with a suffix.
+	 * Return the base_url from configuration
 	 */
-	public static function getBaseUrl() {
+	public static function getBaseUrl(): string {
 		$conf = Minz_Configuration::get('system');
-		$url = rtrim($conf->base_url, '/\\');
+		$url = trim($conf->base_url, ' /\\"');
 		return filter_var($url, FILTER_SANITIZE_URL);
 	}
 
@@ -397,17 +384,11 @@ class Minz_Request {
 		}
 	}
 
-	/**
-	 * @return string
-	 */
-	private static function extractContentType() {
+	private static function extractContentType(): string {
 		return strtolower(trim($_SERVER['CONTENT_TYPE'] ?? ''));
 	}
 
-	/**
-	 * @return boolean
-	 */
-	public static function isPost() {
+	public static function isPost(): bool {
 		return 'POST' === ($_SERVER['REQUEST_METHOD'] ?? '');
 	}