diff options
author | pafgoncalves <pafgoncalves@users.noreply.github.com> | 2016-11-30 21:52:08 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-11-30 21:52:08 +0300 |
commit | fa2fca9512c208e89971661548bf960f991d613d (patch) | |
tree | d7025286fa7a4519d715ca3a52a4cd8ac4ea051e /core/UrlHelper.php | |
parent | ffc37961d811b1922bc94bf3a1173f71562305f9 (diff) |
Add regular expressions to the exclude parameters (#10846)
Allows to use regular expressions in the exclude parameters option.
Doesn't break compatibility if the parameter is not a regular expression, doing a strict compare.
"/.*/" can be used to exclude all parameters.
* Changed the UI texts to explain that the excluding parameters list supports regular expressions.
Added unit tests.
Diffstat (limited to 'core/UrlHelper.php')
-rw-r--r-- | core/UrlHelper.php | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/core/UrlHelper.php b/core/UrlHelper.php index 66a0e64e25..ae4f3c622d 100644 --- a/core/UrlHelper.php +++ b/core/UrlHelper.php @@ -17,6 +17,32 @@ use Piwik\Intl\Data\Provider\RegionDataProvider; */ class UrlHelper { + + /** + * Checks if a string matches/is equal to one of the patterns/strings. + * + * @static + * @param $test String to test. + * @param $patterns Array of strings or regexs. + * + * @return true if $test matches or is equal to one of the regex/string in $patterns, false otherwise. + */ + protected static function in_array_reg($test, $patterns) + { + foreach($patterns as $val) { + if(@preg_match($val, null) === false) { + if( strcasecmp($val, $test) === 0 ) { + return true; + } + } else { + if( preg_match($val, $test) === 1 ) { + return true; + } + } + } + return false; + } + /** * Converts an array of query parameter name/value mappings into a query string. * Parameters that are in `$parametersToExclude` will not appear in the result. @@ -36,7 +62,7 @@ class UrlHelper // decode encoded square brackets $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name); - if (!in_array(strtolower($name), $parametersToExclude)) { + if (!self::in_array_reg(strtolower($name), $parametersToExclude)) { if (is_array($value)) { foreach ($value as $param) { if ($param === false) { |