Commit 323d7493 authored by Ghada El-Zoghbi's avatar Ghada El-Zoghbi Committed by Robert Lyon

Bug 1832803: Check for empty string before passing it to DOMDocument

If an empty string is passed to the DOMDocument, a warning is
generated. Avoid the warning by checking for an empty string.

Sponsored by The Australian National University

behatnotneeded

Change-Id: I4bd3982de81f6db97601a1dbe5232d344e87ca81
parent bbc9b215
...@@ -1172,12 +1172,15 @@ class ArtefactTypeComment extends ArtefactType { ...@@ -1172,12 +1172,15 @@ class ArtefactTypeComment extends ArtefactType {
/* /*
* Removes the classes from the text of the comment thst could interfere * Removes the classes from the text of the comment that could interfere
* with the comment display * with the comment display
* @param string $comment the text content of the comment * @param string $comment the text content of the comment
*/ */
public static function remove_comments_classes($comment) { public static function remove_comments_classes($comment) {
if (empty($comment)) {
return "";
}
$dom = new DOMDocument(); $dom = new DOMDocument();
$dom->preserveWhiteSpace = false; $dom->preserveWhiteSpace = false;
$dom->formatOutput = true; $dom->formatOutput = true;
......
...@@ -380,15 +380,17 @@ class BehatDataGenerators extends BehatBase { ...@@ -380,15 +380,17 @@ class BehatDataGenerators extends BehatBase {
* @param array ('field' => 'values', ...) $record * @param array ('field' => 'values', ...) $record
* @return $record * @return $record
*/ */
public function normalise(&$record) { public function normalise($availablefields, &$record) {
foreach ($record as &$value) { foreach ($record as $fieldname => &$value) {
$value = trim($value); if ($availablefields[$fieldname] == 'bool') {
// Normalise boolean values $value = trim($value);
if (strtolower($value) == 'on' || $value == '1' || $value == 'true') { // Normalise boolean values
$value = true; if (strtolower($value) == 'on' || $value == '1' || $value == 'yes' || $value == 'true') {
} $value = true;
else if (strtolower($value) == 'off' || $value == '0' || $value == 'false') { }
$value = false; else if (strtolower($value) == 'off' || $value == '0' || $value == 'no' || $value == 'false') {
$value = false;
}
} }
} }
} }
...@@ -447,7 +449,7 @@ class BehatDataGenerators extends BehatBase { ...@@ -447,7 +449,7 @@ class BehatDataGenerators extends BehatBase {
foreach ($data->getHash() as $elementdata) { foreach ($data->getHash() as $elementdata) {
// Normalise field values // Normalise field values
$this->normalise($elementdata); $this->normalise($availablefields, $elementdata);
// Validate available fields for given element // Validate available fields for given element
$this->validate_fields($availablefields, $elementdata); $this->validate_fields($availablefields, $elementdata);
// Check if all the required fields are there. // Check if all the required fields are there.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment