Skip to content

Commit b509090

Browse files
author
wrongecho
committed
Detect and convert non-UTF8 encoding as part of input sanitization
1 parent c5e13fd commit b509090

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

functions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,14 @@ function sanitizeInput($input)
733733
{
734734
global $mysqli;
735735

736+
// Detect encoding
737+
$encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1', 'Windows-1252', 'ISO-8859-15'], true);
738+
739+
// If not UTF-8, convert to UTF8 (primarily Windows-1252 is problematic)
740+
if ($encoding !== 'UTF-8') {
741+
$input = mb_convert_encoding($input, 'UTF-8', $encoding);
742+
}
743+
736744
// Remove HTML and PHP tags
737745
$input = strip_tags((string) $input);
738746

0 commit comments

Comments
 (0)