MDL-84351 url: Add method for getting slashargument

This commit is contained in:
David Woloszyn
2025-04-09 16:51:27 +07:00
committed by Huong Nguyen
parent 8733010253
commit ef8cf9fdce
3 changed files with 25 additions and 0 deletions
+13
View File
@@ -336,6 +336,19 @@ final class moodle_url_test extends \advanced_testcase {
$this->assertMatchesRegularExpression($expected, $url->out(true));
}
/**
* Test the get_slashargument method.
*/
public function test_get_slashargument(): void {
$this->resetAfterTest();
$url = new \moodle_url('/pluginfile.php/14/user/private/capybara.png');
$this->assertEquals('/14/user/private/capybara.png', $url->get_slashargument());
$url = new \moodle_url('/image/capybara.png');
$this->assertEmpty($url->get_slashargument());
}
/**
* Data provider for make_pluginfile_url tests.
*
+1
View File
@@ -4,6 +4,7 @@ information provided here is intended especially for developers.
=== 4.3.12 ===
* A new method, `core_text::trim_ctrl_chars()`, has been introduced to clean control characters from text.
This ensures cleaner input handling and prevents issues caused by invisible or non-printable characters
* The public method `get_slashargument` has been added to the `moodle_url` class.
=== 4.3.8 ===
+11
View File
@@ -1024,6 +1024,17 @@ class moodle_url {
public function get_port() {
return $this->port;
}
/**
* Returns the 'slashargument' portion of a URL. For example, if the URL is
* http://www.example.org.com/pluginfile.php/1/core_admin/logocompact/ then this will
* return '1/core_admin/logocompact/'.
*
* @return string Slash argument as string.
*/
public function get_slashargument(): string {
return $this->slashargument;
}
}
/**