Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core/Http
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2014-10-10 13:14:14 +0400
committerMatthieu Napoli <matthieu@mnapoli.fr>2014-10-10 13:14:14 +0400
commitcf2fa5ff7579a49d80f4459ef812fb2949768e27 (patch)
tree066b34d075e0c5c54cfb65fd5230ed281b8aa37e /core/Http
parent9bf1cff4a8e89e485c20a0698ad8c00b6937a950 (diff)
Refactored #6404 into a separate UrlFilter class with dedicated unit tests
Diffstat (limited to 'core/Http')
-rw-r--r--core/Http/UrlFilter.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/core/Http/UrlFilter.php b/core/Http/UrlFilter.php
new file mode 100644
index 0000000000..d9d5528799
--- /dev/null
+++ b/core/Http/UrlFilter.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Http;
+
+use Piwik\Url;
+
+/**
+ * Filters URLs.
+ */
+class UrlFilter
+{
+ /**
+ * Filters some malformed URL by suggesting to redirect them.
+ *
+ * E.g. /index.php/.html?... can be interpreted as HTML by old browsers
+ * even though the Content-Type says JSON.
+ * @link https://github.com/piwik/piwik/issues/6156
+ *
+ * @param string $url The URL to filter.
+ *
+ * @return string|null If not null, then the application should redirect to that URL.
+ */
+ public function filterUrl($url)
+ {
+ $path = parse_url($url, PHP_URL_PATH);
+
+ if (strpos($path, 'index.php/') !== false) {
+ return preg_replace('#index\.php/([^\?]*)#', 'index.php', $url, 1);
+ }
+
+ return null;
+ }
+}