diff options
author | Nina Pypchenko <22447785+nina-py@users.noreply.github.com> | 2021-01-01 08:13:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-01 08:13:19 +0300 |
commit | df68fbce2397570df2d5fee6c1b56db57241a10b (patch) | |
tree | 3951c42445243381d95452a7f1fd0b1aa194d52d /core | |
parent | 8886c9065cf11d5ac0628a300d9c55fb1e154853 (diff) |
Add regular expression support to list of user agents to exclude (#16766)
* Add regular expression support to list of user agents to exclude
- Added regex support to Administration -> Websites -> Settings ->
Global list of user agents to exclude
- Made sure old tests that use stripos() pass
- Added new tests
- Added a sentence to the inline help area about regex support
- Fixed a typo elsewhere as specified in the original issue.
Closes #14186.
Updated method and tests following code review
Update plugins/WebsiteMeasurable/MeasurableSettings.php
Co-authored-by: Stefan Giehl <stefan@matomo.org>
Update system tests
* Update screenshots for UI tests affected by the copy changes
Diffstat (limited to 'core')
-rw-r--r-- | core/Tracker/VisitExcluded.php | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/core/Tracker/VisitExcluded.php b/core/Tracker/VisitExcluded.php index 243618bc51..8d412cef26 100644 --- a/core/Tracker/VisitExcluded.php +++ b/core/Tracker/VisitExcluded.php @@ -349,12 +349,13 @@ class VisitExcluded * Returns true if the specified user agent should be excluded for the current site or not. * * Visits whose user agent string contains one of the excluded_user_agents strings for the - * site being tracked (or one of the global strings) will be excluded. + * site being tracked (or one of the global strings) will be excluded. Regular expressions + * are also supported. * * @internal param string $this ->userAgent The user agent string. * @return bool */ - protected function isUserAgentExcluded() + protected function isUserAgentExcluded(): bool { $excludedAgents = $this->getAttributes('excluded_user_agents', 'global_excluded_user_agents'); @@ -364,6 +365,10 @@ class VisitExcluded if (stripos($this->userAgent, $excludedUserAgent) !== false) { return true; } + // if the string is a valid regex, and the user agent matches, this visit should be excluded + if (@preg_match($excludedUserAgent, null) !== false) { + return preg_match($excludedUserAgent, $this->userAgent) ? true : false; + } } } |