mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 09:14:08 +02:00
parent
4ddc0e718b
commit
f2ed813c9a
@ -130,7 +130,7 @@ class Url
|
|||||||
// Fetch fragment manually and remove it from the url, to 'help' the parse_url() function
|
// Fetch fragment manually and remove it from the url, to 'help' the parse_url() function
|
||||||
// parsing the url properly. Otherwise calling the function with a fragment, but without a
|
// parsing the url properly. Otherwise calling the function with a fragment, but without a
|
||||||
// query will cause unpredictable behaviour.
|
// query will cause unpredictable behaviour.
|
||||||
$url = self::stripUrlFragment($url);
|
$fragment = self::stripUrlFragment($url);
|
||||||
$urlParts = parse_url($url);
|
$urlParts = parse_url($url);
|
||||||
if (isset($urlParts['path'])) {
|
if (isset($urlParts['path'])) {
|
||||||
if ($baseUrl !== '' && strpos($urlParts['path'], $baseUrl) === 0) {
|
if ($baseUrl !== '' && strpos($urlParts['path'], $baseUrl) === 0) {
|
||||||
@ -144,8 +144,7 @@ class Url
|
|||||||
$params = UrlParams::fromQueryString($urlParts['query'])->mergeValues($params);
|
$params = UrlParams::fromQueryString($urlParts['query'])->mergeValues($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fragment = self::getUrlFragment($url);
|
if ($fragment) {
|
||||||
if ($fragment !== '') {
|
|
||||||
$urlObject->setAnchor($fragment);
|
$urlObject->setAnchor($fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,34 +153,20 @@ class Url
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the fragment of a given url
|
* Remove the fragment-part of a given url and return it
|
||||||
*
|
*
|
||||||
* @param string $url The url containing the fragment.
|
* @param string $url The url to strip its fragment from
|
||||||
*
|
*
|
||||||
* @return string The fragment without the '#'
|
* @return null|string The stripped fragment, without the '#'
|
||||||
*/
|
*/
|
||||||
protected static function getUrlFragment($url)
|
protected static function stripUrlFragment(&$url)
|
||||||
{
|
{
|
||||||
$url = parse_url($url);
|
if (preg_match('@#(.*)$@', $url, $matches)) {
|
||||||
if (isset($url['fragment'])) {
|
$url = str_replace('#' . $matches[1], '', $url);
|
||||||
return $url['fragment'];
|
return $matches[1];
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the fragment-part of a given url
|
|
||||||
*
|
|
||||||
* @param string $url The url to strip from its fragment
|
|
||||||
*
|
|
||||||
* @return string The url without the fragment
|
|
||||||
*/
|
|
||||||
protected static function stripUrlFragment($url)
|
|
||||||
{
|
|
||||||
return preg_replace('/#.*$/', '', $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrite the baseUrl
|
* Overwrite the baseUrl
|
||||||
*
|
*
|
||||||
|
24
test/php/regression/Bug6284Test.php
Normal file
24
test/php/regression/Bug6284Test.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Tests\Icinga\Regression;
|
||||||
|
|
||||||
|
use Icinga\Test\BaseTestCase;
|
||||||
|
use Icinga\Web\Url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression-Test for bug #6284
|
||||||
|
*
|
||||||
|
* href-helper drops URL fragments.
|
||||||
|
*
|
||||||
|
* @see https://dev.icinga.org/issues/6284
|
||||||
|
*/
|
||||||
|
class Bug6284Test extends BaseTestCase
|
||||||
|
{
|
||||||
|
public function testWhetherUrlFromPathDoesNotDropFragments()
|
||||||
|
{
|
||||||
|
$url = 'some/route/with#anchor';
|
||||||
|
$this->assertEquals($url, Url::fromPath($url)->getRelativeUrl());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user