mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-76362 core: Short-circuit strip_querystring on empty values
This commit is contained in:
parent
b0aa0b63e0
commit
19bedb8eba
@ -23,9 +23,7 @@
|
||||
* @author T.J.Hunt@open.ac.uk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
*/
|
||||
|
||||
class weblib_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* @covers ::format_string
|
||||
*/
|
||||
@ -1119,4 +1117,32 @@ EXPECTED;
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for strip_querystring tests.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function strip_querystring_provider(): array {
|
||||
return [
|
||||
'Null' => [null, ''],
|
||||
'Empty string' => ['', ''],
|
||||
'No querystring' => ['https://example.com', 'https://example.com'],
|
||||
'Querystring' => ['https://example.com?foo=bar', 'https://example.com'],
|
||||
'Querystring with fragment' => ['https://example.com?foo=bar#baz', 'https://example.com'],
|
||||
'Querystring with fragment and path' => ['https://example.com/foo/bar?foo=bar#baz', 'https://example.com/foo/bar'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the strip_querystring function with various exampels.
|
||||
*
|
||||
* @dataProvider strip_querystring_provider
|
||||
* @param mixed $value
|
||||
* @param mixed $expected
|
||||
* @covers ::strip_querystring
|
||||
*/
|
||||
public function test_strip_querystring($value, $expected): void {
|
||||
$this->assertEquals($expected, strip_querystring($value));
|
||||
}
|
||||
}
|
||||
|
@ -148,8 +148,11 @@ function addslashes_js($var) {
|
||||
* @return string The remaining URL.
|
||||
*/
|
||||
function strip_querystring($url) {
|
||||
if ($url === null || $url === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($commapos = strpos($url ?? '', '?')) {
|
||||
if ($commapos = strpos($url, '?')) {
|
||||
return substr($url, 0, $commapos);
|
||||
} else {
|
||||
return $url;
|
||||
|
Loading…
x
Reference in New Issue
Block a user