Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.9
-
Fix Version/s: 1.9.1
-
Component/s: Accessibility, Language
-
Labels:None
-
Affected Branches:MOODLE_19_STABLE
-
Fixed Branches:MOODLE_19_STABLE
Description
When a string containing a entity is displayed by Javascript in an alert window, the entity is not interpreted, but written litteraly.
Example (occuring when taking a quiz attempt with a time limit, in french language):
$string['confirmstarttimelimit'] = 'Le temps pour effectuer ce test est limité. Voulez-vous vraiment le commencer ?' (quiz.php in french language pack)
- function addslashes_js($strconfirmstartattempt) is called in /mod/quiz/accessrules.php (line 684)
- var $strconfirmstartattempt is defined by calling print_start_attempt_button() (line 204)
- function confirm_start_attempt_message () is called by print_start_attempt_button()
- function getstring is called by confirm_start_attempt_message() (line 319)
This could maybe be fixed by calling html_entity_decode() on the string before addslashes_js().
Issue Links
| This issue has a non-specific relationship to: | ||||
| MDL-13975 | p() and s() should not be used to print lang strings |
|
|
|
For PHP before 4.3.0, one could use (see http://ch2.php.net/manual/fr/function.html-entity-decode.php):
function html_entity_decode_php4 ($string)
{
// Replaces numerical entities
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("
1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr("
1")', $string);
// Replaces litteral entities
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
return strtr ($string, $trans_tbl);
}
1"))', $string); $string = preg_replace('~&#([0-9]+);~e', 'chr("
1")', $string); // Replaces litteral entities $trans_tbl = get_html_translation_table (HTML_ENTITIES); $trans_tbl = array_flip ($trans_tbl); return strtr ($string, $trans_tbl); }