diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php
index ce2a0ea966..1596e015be 100644
--- a/src/Util/ParseUrl.php
+++ b/src/Util/ParseUrl.php
@@ -204,7 +204,7 @@ class ParseUrl
$charset = '';
// Look for a charset, first in headers
// Expected form: Content-Type: text/html; charset=ISO-8859-4
- if (preg_match('/charset=(.+?)\s/', $header, $matches)) {
+ if (preg_match('/charset=([a-z0-9-_.\/]+)/i', $header, $matches)) {
$charset = trim(trim(trim(array_pop($matches)), ';,'));
}
@@ -212,14 +212,18 @@ class ParseUrl
// Expected forms:
// -
// -
+ // -
+ // -
// We escape