Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-21382 mform: escape invalid characters when generating javascript…

… validation function name

This patch fixes the support for addGroupRule in cases when the element
name contains invalid characters like square brackets (that is if the
group element is an array element).

Credit goes to Hubert Chathi for the solution and the patch provided.
  • Loading branch information...
commit 82b7f70bf45812a397444d7c1a91145466d2f510 1 parent 50978a0
David Mudrák authored September 17, 2010

Showing 1 changed file with 7 additions and 3 deletions. Show diff stats Hide diff stats

  1. 10  lib/formslib.php
10  lib/formslib.php
@@ -1349,8 +1349,12 @@ function qf_errorHandler(element, _qfMsg) {
1349 1349
             //unset($element);
1350 1350
             list($jsArr,$element)=$jsandelement;
1351 1351
             //end of fix
  1352
+            $escapedElementName = preg_replace_callback(
  1353
+                '/[_\[\]]/',
  1354
+                create_function('$matches', 'return sprintf("_%2x",ord($matches[0]));'),
  1355
+                $elementName);
1352 1356
             $js .= '
1353  
-function validate_' . $this->_formName . '_' . $elementName . '(element) {
  1357
+function validate_' . $this->_formName . '_' . $escapedElementName . '(element) {
1354 1358
   var value = \'\';
1355 1359
   var errFlag = new Array();
1356 1360
   var _qfGroups = {};
@@ -1364,7 +1368,7 @@ function validate_' . $this->_formName . '_' . $elementName . '(element) {
1364 1368
 }
1365 1369
 ';
1366 1370
             $validateJS .= '
1367  
-  ret = validate_' . $this->_formName . '_' . $elementName.'(frm.elements[\''.$elementName.'\']) && ret;
  1371
+  ret = validate_' . $this->_formName . '_' . $escapedElementName.'(frm.elements[\''.$elementName.'\']) && ret;
1368 1372
   if (!ret && !first_focus) {
1369 1373
     first_focus = true;
1370 1374
     frm.elements[\''.$elementName.'\'].focus();
@@ -1375,7 +1379,7 @@ function validate_' . $this->_formName . '_' . $elementName . '(element) {
1375 1379
             //unset($element);
1376 1380
             //$element =& $this->getElement($elementName);
1377 1381
             //end of fix
1378  
-            $valFunc = 'validate_' . $this->_formName . '_' . $elementName . '(this)';
  1382
+            $valFunc = 'validate_' . $this->_formName . '_' . $escapedElementName . '(this)';
1379 1383
             $onBlur = $element->getAttribute('onBlur');
1380 1384
             $onChange = $element->getAttribute('onChange');
1381 1385
             $element->updateAttributes(array('onBlur' => $onBlur . $valFunc,

0 notes on commit 82b7f70

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