Skip to content

Commit

Permalink
MDL-76362 core: Short circuit s() on empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 23, 2023
1 parent 19bedb8 commit 5d3cb79
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,18 @@
* @return string
*/
function s($var) {

if ($var === false) {
return '0';
}

return preg_replace('/&#(\d+|x[0-9a-f]+);/i', '&#$1;',
htmlspecialchars($var ?? '', ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE));
if ($var === null || $var === '') {
return '';
}

return preg_replace(
'/&#(\d+|x[0-9a-f]+);/i', '&#$1;',
htmlspecialchars($var, ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE)
);
}

/**
Expand Down

0 comments on commit 5d3cb79

Please sign in to comment.