diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index e45fbe8b8f..caf3cc893f 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -102,21 +102,11 @@ if ( ! function_exists('base_url')) $path = implode('/', $path); } - // We should be using the set baseURL the user set - // otherwise get rid of the path because we have + // We should be using the configured baseURL that the user set; + // otherwise get rid of the path, because we have // no way of knowing the intent... $config = \CodeIgniter\Config\Services::request()->config; - - if ( ! empty($config->baseURL)) - { - $url = new \CodeIgniter\HTTP\URI($config->baseURL); - } - else - { - $url = \CodeIgniter\Config\Services::request($config, false)->uri; - $url->setPath('/'); - } - + $url = new \CodeIgniter\HTTP\URI($config->baseURL); unset($config); // Merge in the path set by the user, if any @@ -402,7 +392,7 @@ if ( ! function_exists('safe_mailto')) $x = str_split(' '', - '[^\w\d _-]' => '', - '\s+' => $separator, - '(' . $q_separator . ')+' => $separator + '&.+?;' => '', + '[^\w\d _-]' => '', + '\s+' => $separator, + '(' . $q_separator . ')+' => $separator ]; $str = strip_tags($str); diff --git a/tests/system/Helpers/URLHelperTest.php b/tests/system/Helpers/URLHelperTest.php index 57488de49a..e1ecc48036 100644 --- a/tests/system/Helpers/URLHelperTest.php +++ b/tests/system/Helpers/URLHelperTest.php @@ -187,8 +187,6 @@ class URLHelperTest extends \CIUnitTestCase $this->assertEquals('http://example.com/index.php/', site_url()); } - //-------------------------------------------------------------------- - /** * @see https://github.com/bcit-ci/CodeIgniter4/issues/240 */ @@ -209,8 +207,6 @@ class URLHelperTest extends \CIUnitTestCase $this->assertEquals('http://example.com/index.php/profile', site_url('profile')); } - //-------------------------------------------------------------------- - //-------------------------------------------------------------------- // Test base_url @@ -289,8 +285,6 @@ class URLHelperTest extends \CIUnitTestCase $this->assertEquals('http://example.com/', base_url()); } - //-------------------------------------------------------------------- - /** * @see https://github.com/bcit-ci/CodeIgniter4/issues/867 */ @@ -323,8 +317,6 @@ class URLHelperTest extends \CIUnitTestCase $this->assertEquals('http://example.com/profile', base_url('profile')); } - //-------------------------------------------------------------------- - //-------------------------------------------------------------------- // Test current_url @@ -856,6 +848,8 @@ class URLHelperTest extends \CIUnitTestCase { $this->assertEquals('http://codeigniter.com', prep_url('codeigniter.com')); $this->assertEquals('http://www.codeigniter.com', prep_url('www.codeigniter.com')); + $this->assertEquals('', prep_url()); + $this->assertEquals('http://www.codeigniter.com', prep_url('http://www.codeigniter.com')); } //--------------------------------------------------------------------