From ef8cf9fdcee23e1cb3f5950d980ee7f3ea1a73ec Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Fri, 7 Feb 2025 12:25:00 +1100 Subject: [PATCH] MDL-84351 url: Add method for getting slashargument --- lib/tests/moodle_url_test.php | 13 +++++++++++++ lib/upgrade.txt | 1 + lib/weblib.php | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/lib/tests/moodle_url_test.php b/lib/tests/moodle_url_test.php index ac9ee8c4ee2..bb5d4ce683e 100644 --- a/lib/tests/moodle_url_test.php +++ b/lib/tests/moodle_url_test.php @@ -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. * diff --git a/lib/upgrade.txt b/lib/upgrade.txt index b9d5f6a944f..11fdbf75363 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -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 === diff --git a/lib/weblib.php b/lib/weblib.php index e53d5916eae..3f01c21200f 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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; + } } /**