From 4e22073a9bbd21b3cde54a64394d9bc061ee2290 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 26 Nov 2024 11:33:20 +0800 Subject: [PATCH] MDL-83811 core: Make sure to trim leading backslashes too for Windows --- lib/tests/component_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tests/component_test.php b/lib/tests/component_test.php index 29f88ad1aa9..b8825588c32 100644 --- a/lib/tests/component_test.php +++ b/lib/tests/component_test.php @@ -1349,10 +1349,10 @@ final class component_test extends \advanced_testcase { foreach ($paths as $path) { // The composer.json can specify any arbitrary directory within the folder. - // It always contains a leading slash (/). + // It always contains a leading slash (/) or backslash (\) on Windows. // It may also have an optional trailing slash (/). // Concatenate the parts and removes the slashes. - $relativenamespacepath = trim("{$relativepath}/{$path}", '/'); + $relativenamespacepath = trim("{$relativepath}/{$path}", '/\\'); // The Moodle PSR-4 autoloader data has two formats: // - a string, for a single source; or @@ -1377,7 +1377,7 @@ final class component_test extends \advanced_testcase { // The Moodle composer file autoloads are a simple string[]. $autoloadnamefiles = $rc->getProperty('composerautoloadfiles')->getValue(null); foreach ($composer['autoload']['files'] as $file) { - $this->assertContains(trim($relativepath, '/') . "/{$file}", $autoloadnamefiles); + $this->assertContains(trim($relativepath, '/\\') . "/{$file}", $autoloadnamefiles); } } }