From 987ead271955935be850b9e4ac2435912cd494f6 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 3 Nov 2022 07:47:50 +0100 Subject: [PATCH] ensure the basepath ends in a slash, if one is set --- lib/Configuration.php | 8 ++++++++ tst/JsonApiTest.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Configuration.php b/lib/Configuration.php index 6f3a822..5588791 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -236,6 +236,14 @@ class Configuration if (!array_key_exists($this->_configuration['expire']['default'], $this->_configuration['expire_options'])) { $this->_configuration['expire']['default'] = key($this->_configuration['expire_options']); } + + // ensure the basepath ends in a slash, if one is set + if ( + strlen($this->_configuration['main']['basepath']) && + substr_compare($this->_configuration['main']['basepath'], '/', -1) !== 0 + ) { + $this->_configuration['main']['basepath'] .= '/'; + } } /** diff --git a/tst/JsonApiTest.php b/tst/JsonApiTest.php index 5c50843..61a2870 100644 --- a/tst/JsonApiTest.php +++ b/tst/JsonApiTest.php @@ -272,7 +272,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase { $mock_yourls_service = $this->_path . DIRECTORY_SEPARATOR . 'yourls.json'; $options = parse_ini_file(CONF, true); - $options['main']['basepath'] = 'https://example.com/path/'; + $options['main']['basepath'] = 'https://example.com/path'; // missing slash gets added by Configuration constructor $options['main']['urlshortener'] = 'https://example.com/path/shortenviayourls?link='; $options['yourls']['apiurl'] = $mock_yourls_service; Helper::createIniFile(CONF, $options);