mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-47073 lib: Replace backslashes with slashes in jquery plugin urls
This patch replaces backslash characters in the generated jQuery plugin URL to forward slashes when slasharguments is disabled and the Moodle server is running on IIS. Thanks to Ryan Panning <Ryan.Panning@district196.org> for reporting this issue and for suggesting a fix.
This commit is contained in:
parent
821ab27c19
commit
bbbdfc8610
@ -556,6 +556,8 @@ class page_requirements_manager {
|
||||
$path = realpath("$componentdir/jquery/$file");
|
||||
if (strpos($path, $CFG->dirroot) === 0) {
|
||||
$url = $CFG->httpswwwroot.preg_replace('/^'.preg_quote($CFG->dirroot, '/').'/', '', $path);
|
||||
// Replace all occurences of backslashes characters in url to forward slashes.
|
||||
$url = str_replace('\\', '/', $url);
|
||||
$url = new moodle_url($url);
|
||||
} else {
|
||||
// Bad luck, fix your server!
|
||||
|
@ -63,4 +63,42 @@ class core_outputrequirementslib_testcase extends advanced_testcase {
|
||||
$this->assertTrue($secondpage->requires->should_create_one_time_item_now('test_item'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the jquery_plugin method.
|
||||
*
|
||||
* Test to make sure that backslashes are not generated with either slasharguments set to on or off.
|
||||
*/
|
||||
public function test_jquery_plugin() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// With slasharguments on.
|
||||
$CFG->slasharguments = 1;
|
||||
|
||||
$page = new moodle_page();
|
||||
$requirements = $page->requires;
|
||||
// Assert successful method call.
|
||||
$this->assertTrue($requirements->jquery_plugin('jquery'));
|
||||
$this->assertTrue($requirements->jquery_plugin('ui'));
|
||||
|
||||
// Get the code containing the required jquery plugins.
|
||||
$requirecode = $requirements->get_top_of_body_code();
|
||||
// Make sure that the generated code does not contain backslashes.
|
||||
$this->assertFalse(strpos($requirecode, '\\'), "Output contains backslashes: " . $requirecode);
|
||||
|
||||
// With slasharguments off.
|
||||
$CFG->slasharguments = 0;
|
||||
|
||||
$page = new moodle_page();
|
||||
$requirements = $page->requires;
|
||||
// Assert successful method call.
|
||||
$this->assertTrue($requirements->jquery_plugin('jquery'));
|
||||
$this->assertTrue($requirements->jquery_plugin('ui'));
|
||||
|
||||
// Get the code containing the required jquery plugins.
|
||||
$requirecode = $requirements->get_top_of_body_code();
|
||||
// Make sure that the generated code does not contain backslashes.
|
||||
$this->assertFalse(strpos($requirecode, '\\'), "Output contains backslashes: " . $requirecode);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user