From d76b8a20686dfe4cae51c7366c96b71dac4211e3 Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Mon, 22 Jun 2009 02:59:02 +0000 Subject: [PATCH] ajaxlib MDL-16693 Fixed fringe condition in ajaxlib and added test --- lib/ajax/ajaxlib.php | 3 ++- lib/ajax/simpletest/testajaxlib.php | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index 725923970b..7bdbc3a457 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -119,7 +119,8 @@ class page_requirements_manager { public function js($jsfile, $fullurl = false) { global $CFG; if (!$fullurl) { - if (!file_exists($CFG->dirroot . '/' . $jsfile)) { + // strtok is used to trim off any GET string arguments before looking for the file + if (!file_exists($CFG->dirroot . '/' . strtok($jsfile, '?'))) { throw new coding_exception('Attept to require a JavaScript file that does not exist.', $jsfile); } $url = $CFG->httpswwwroot . '/' . $jsfile; diff --git a/lib/ajax/simpletest/testajaxlib.php b/lib/ajax/simpletest/testajaxlib.php index 1b144cad2f..aed4e16956 100644 --- a/lib/ajax/simpletest/testajaxlib.php +++ b/lib/ajax/simpletest/testajaxlib.php @@ -320,6 +320,15 @@ class page_requirements_manager_test extends ajaxlib_unit_test_base { $this->assertContains($html, $CFG->httpswwwroot . '/' . $jsfile); } + public function test_requiring_js_with_argument() { + global $CFG; + $jsfile = 'lib/javascript-static.js?d=434'; // Just needs to be a JS file that exists. + $this->requires->js($jsfile); + + $html = $this->requires->get_end_code(); + $this->assertContains($html, $CFG->httpswwwroot . '/' . $jsfile); + } + public function test_nonexistant_js_throws_exception() { $cssfile = 'js/file/that/does/not/exist.js'; -- 2.39.5