From 4f65d03b082e49e6acf60b101f7f67bef4240f4a Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Sat, 16 Mar 2013 20:42:55 +0000 Subject: [PATCH] MDL-38515 JavaScript: Detect use of invalid module names in YUI dependencies A warning is shown in the browser console if debugging is set, but it is not possible to return from the configFn and stop the module load attempt from continuing. The error is caught and an additional error is shown by yui_combo.php --- lib/outputrequirementslib.php | 2 +- theme/yui_combo.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index 48bc0f71a34..ffc29c354ae 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -197,7 +197,7 @@ class page_requirements_manager { ) ) )); - $configname = $this->YUI_config->set_config_function("var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'-min.'+me.type;"); + $configname = $this->YUI_config->set_config_function("var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (!b.length) {Y.log('Attempt to load invalid module name: ' + me.name, 'error'); return;} if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'-min.'+me.type;"); $this->YUI_config->add_group('moodle', array( 'name' => 'moodle', 'base' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep.'moodle/'.$jsrev.'/', diff --git a/theme/yui_combo.php b/theme/yui_combo.php index 4c136b60708..36f2694186b 100644 --- a/theme/yui_combo.php +++ b/theme/yui_combo.php @@ -83,6 +83,11 @@ foreach ($parts as $part) { //debug($bits); $version = array_shift($bits); if ($version === 'moodle') { + if (count($bits) <= 3) { + // This is an invalid module load attempt. + $content .= "\n// Incorrect moodle module inclusion. Not enough component information in {$part}.\n"; + continue; + } if (!defined('ABORT_AFTER_CONFIG_CANCEL')) { define('ABORT_AFTER_CONFIG_CANCEL', true); define('NO_UPGRADE_CHECK', true); -- 2.43.0