Skip to content
Browse files

MDL-38515 JavaScript: Detect use of invalid module names in YUI depen…

…dencies

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
  • Loading branch information...
1 parent 09fe13d commit 4f65d03b082e49e6acf60b101f7f67bef4240f4a @andrewnicols andrewnicols committed
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/outputrequirementslib.php
  2. +5 −0 theme/yui_combo.php
View
2 lib/outputrequirementslib.php
@@ -197,7 +197,7 @@ public function __construct() {
)
)
));
- $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.'/',
View
5 theme/yui_combo.php
@@ -83,6 +83,11 @@
//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);

0 comments on commit 4f65d03

Please sign in to comment.
Something went wrong with that request. Please try again.