Skip to content
Snippets Groups Projects
Commit 670bf5c5 authored by Peter Rotich's avatar Peter Rotich
Browse files

html: Replace htmlentities with htmlspecialchars

parent cf4b4cea
Branches
Tags
No related merge requests found
...@@ -275,7 +275,12 @@ class Format { ...@@ -275,7 +275,12 @@ class Format {
return $striptags?Format::striptags($text, false):$text; return $striptags?Format::striptags($text, false):$text;
} }
function htmlchars($var) { function htmlchars($var, $sanitize = false) {
//XXX: should we decode first?
$var = Format::htmldecode($var);
if ($sanitize)
$var = Format::sanitize($var);
return Format::htmlencode($var); return Format::htmlencode($var);
} }
...@@ -293,7 +298,7 @@ class Format { ...@@ -293,7 +298,7 @@ class Format {
$flags |= ENT_HTML401; $flags |= ENT_HTML401;
try { try {
return htmlentities( (string) $var, $flags, 'UTF-8', false); return htmlspecialchars( (string) $var, $flags, 'UTF-8', false);
} catch(Exception $e) { } catch(Exception $e) {
return $var; return $var;
} }
...@@ -308,7 +313,7 @@ class Format { ...@@ -308,7 +313,7 @@ class Format {
if (phpversion() >= '5.4.0') if (phpversion() >= '5.4.0')
$flags |= ENT_HTML401; $flags |= ENT_HTML401;
return html_entity_decode($var, $flags, 'UTF-8'); return htmlspecialchars_decode($var, $flags);
} }
function input($var) { function input($var) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment