diff options
author | Stefan Giehl <stefan@matomo.org> | 2020-05-17 23:39:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 23:39:32 +0300 |
commit | b6ace0e06c2ef3f8f98ac55feb934ebe0d304107 (patch) | |
tree | f257e7b38af89a61c4e15e8aef2a854882676570 /core/Tracker/Request.php | |
parent | d89c2b7fb4b295542204cd5d81c35f79b5c93489 (diff) |
Use utf8mb4 character set if possible (#15618)
Diffstat (limited to 'core/Tracker/Request.php')
-rw-r--r-- | core/Tracker/Request.php | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index 48fecc103b..77c5795804 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -13,6 +13,7 @@ use Piwik\Common; use Piwik\Config; use Piwik\Container\StaticContainer; use Piwik\Cookie; +use Piwik\DbHelper; use Piwik\Exception\InvalidRequestParameterException; use Piwik\Exception\UnexpectedWebsiteFoundException; use Piwik\IP; @@ -87,13 +88,19 @@ class Request } } - // check for 4byte utf8 characters in all tracking params and replace them with � - // @TODO Remove as soon as our database tables use utf8mb4 instead of utf8 + // check for 4byte utf8 characters in all tracking params and replace them with � if not support by database $this->params = $this->replaceUnsupportedUtf8Chars($this->params); } protected function replaceUnsupportedUtf8Chars($value, $key=false) { + $dbSettings = new \Piwik\Db\Settings(); + $charset = $dbSettings->getUsedCharset(); + + if ('utf8mb4' === $charset) { + return $value; // no need to replace anything if utf8mb4 is supported + } + if (is_string($value) && preg_match('/[\x{10000}-\x{10FFFF}]/u', $value)) { Common::printDebug("Unsupported character detected in $key. Replacing with \xEF\xBF\xBD"); return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |