ensure the basepath ends in a slash, if one is set

This commit is contained in:
El RIDO 2022-11-03 07:47:50 +01:00
parent 432d3e71d3
commit 987ead2719
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
2 changed files with 9 additions and 1 deletions

View File

@ -236,6 +236,14 @@ class Configuration
if (!array_key_exists($this->_configuration['expire']['default'], $this->_configuration['expire_options'])) { if (!array_key_exists($this->_configuration['expire']['default'], $this->_configuration['expire_options'])) {
$this->_configuration['expire']['default'] = key($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'] .= '/';
}
} }
/** /**

View File

@ -272,7 +272,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
{ {
$mock_yourls_service = $this->_path . DIRECTORY_SEPARATOR . 'yourls.json'; $mock_yourls_service = $this->_path . DIRECTORY_SEPARATOR . 'yourls.json';
$options = parse_ini_file(CONF, true); $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['main']['urlshortener'] = 'https://example.com/path/shortenviayourls?link=';
$options['yourls']['apiurl'] = $mock_yourls_service; $options['yourls']['apiurl'] = $mock_yourls_service;
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);