From 09b3a24f30ec7da01a081f6c6aaa7080ddf0248b Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 20 Sep 2017 10:07:32 +1200 Subject: [PATCH 1/2] BUG Detect, warn, and fix invalid SS_BASE_URL Fixes #7362 --- docs/en/04_Changelogs/4.0.0.md | 7 +++++++ src/includes/constants.php | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 3b5caeba6..5dddca074 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -418,6 +418,13 @@ variable set-up process. This generally encouraged bad practice and should be av logic early in the bootstrap, this is best placed in the `_config.php` files. Note also that `$_FILE_TO_URL_MAPPING` has been removed and replaced with `SS_BASE_URL` env var. +This url must be an absolute url with an optional protocol. The following are valid, for example: + +``` +SS_BASE_URL="http://localhost/" +SS_BASE_URL="https://localhost/" +SS_BASE_URL="//localhost/" +``` The global values `$database` and `$databaseConfig` have been deprecated, as has `ConfigureFromEnv.php` which is no longer necessary. diff --git a/src/includes/constants.php b/src/includes/constants.php index a6419097c..27fada010 100644 --- a/src/includes/constants.php +++ b/src/includes/constants.php @@ -72,6 +72,20 @@ if (!getenv('SS_IGNORE_DOT_ENV')) { }); } +// Validate SS_BASE_URL is absolute +if (getenv('SS_BASE_URL') && !preg_match('#^(\w+:)?//.*#', getenv('SS_BASE_URL'))) { + call_user_func(function () { + $base = getenv('SS_BASE_URL'); + user_error( + "SS_BASE_URL should be an absolute url with protocol " + . "(http://$base) or without protocol (//$base)", + E_USER_WARNING + ); + // Treat as protocol-less absolute url + $base = '//' . $base; + putenv("SS_BASE_URL=$base"); + }); +} if (!defined('BASE_URL')) { define('BASE_URL', call_user_func(function () { From 265f91060c2a8da61cb3e3a0de3f2d867809bcda Mon Sep 17 00:00:00 2001 From: Christopher Joe Date: Wed, 20 Sep 2017 12:42:45 +1200 Subject: [PATCH 2/2] Fix phpcs error --- src/Control/ContentNegotiator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/ContentNegotiator.php b/src/Control/ContentNegotiator.php index 8e5f621c3..fd99dc69c 100644 --- a/src/Control/ContentNegotiator.php +++ b/src/Control/ContentNegotiator.php @@ -136,7 +136,7 @@ class ContentNegotiator } $negotiator = new ContentNegotiator(); - $negotiator->$chosenFormat( $response ); + $negotiator->$chosenFormat($response); } /**