MDL-26155 string: Improved validation when constructing lang_strings if debugging is enabled

This commit is contained in:
Sam Hemelryk 2011-12-06 11:30:12 +13:00
parent e106013f34
commit d79883ab7f

View File

@ -10553,6 +10553,10 @@ class lang_string {
* @param string $lang The language to use when processing the string. * @param string $lang The language to use when processing the string.
*/ */
public function __construct($identifier, $component = '', $a = null, $lang = null) { public function __construct($identifier, $component = '', $a = null, $lang = null) {
if (empty($component)) {
$component = 'moodle';
}
$this->identifier = $identifier; $this->identifier = $identifier;
$this->component = $component; $this->component = $component;
$this->lang = $lang; $this->lang = $lang;
@ -10580,6 +10584,18 @@ class lang_string {
} }
} }
} }
if (debugging(false, DEBUG_DEVELOPER)) {
if (clean_param($this->identifier, PARAM_STRINGID) == '') {
throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please check your string definition');
}
if (!empty($this->component) && clean_param($this->component, PARAM_COMPONENT) == '') {
throw new coding_exception('Invalid string compontent. Please check your string definition');
}
if (!get_string_manager()->string_exists($this->identifier, $this->component)) {
debugging('String does not exist. Please check your string definition for '.$this->identifier.'/'.$this->component, DEBUG_DEVELOPER);
}
}
} }
/** /**
@ -10601,7 +10617,7 @@ class lang_string {
if ($this->string === null) { if ($this->string === null) {
// Check the quality of the identifier. // Check the quality of the identifier.
if (clean_param($this->identifier, PARAM_STRINGID) == '') { if (clean_param($this->identifier, PARAM_STRINGID) == '') {
throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please fix your get_string() call and string definition'); throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please check your string definition');
} }
// Process the string // Process the string