Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect overlapping detections #7669

Merged
merged 3 commits into from
Apr 29, 2024
Merged

Detect overlapping detections #7669

merged 3 commits into from
Apr 29, 2024

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Apr 24, 2024

Description:

It seems like we have introduced some overlapping detections recently.
There are various detections that work correctly, when they are parsed by a specific client parser, but when parsed with all parsers another parser overwrites the results.
I've added some tests in this PR that use the fixtures used for specific parsers to parse them fully and check if the result is still the same.
There are currently 31 failures, where that doesn't match anymore.

I think we should try to get rid of overlapping detections. A user agent should either be detected as a browser or a mobile app. But not both.

One of the problematic detections seems to be this one:

# Electron generic apps
- regex: ' (?!(?:AppleWebKit|brave))([a-z0-9]*)(?:-desktop|-electron-app)?/(\d+\.[\d.]+).*Electron/'
name: '$1'
version: '$2'

We might need to rethink the order in which the parsers are added, so such generic matches are done more later.
On the other side could every parser contain generic detections, which might overwrite other results...

Or would it make sense to somehow mark generic regexes so they are only used if nothing else matches?

@liviuconcioiu @sanchezzzhak Any thoughts / ideas on that ?

refs #7668

Review

sanchezzzhak
sanchezzzhak previously approved these changes Apr 24, 2024
@sanchezzzhak
Copy link
Collaborator

sanchezzzhak commented Apr 24, 2024

I don't see any other way out but to add exceptions to the rule
fix for mobile-apps.yaml

# Electron generic apps
- regex:  ' (?!(?:AppleWebKit|brave|Franz|Mailspring|Notion|Basecamp|Evernote|catalyst|ramboxpro|BlueMail|BeakerBrowser|TweakStyle|Colibri|Polypane|VibeMate|(?:d|LT|Glass|Sushi|Flash|OhHai)Browser|Sizzy))([a-z0-9]*)(?:-desktop|-electron-app)?/(\d+\.[\d.]+).*Electron/'
  name: '$1'
  version: '$2'

fix for bot.yaml

# Generic detections
- regex: '[a-z0-9_-]*(?:(?<!cu|power[ _]|m[ _])bot(?![ _]TAB|[ _]?5[0-9]|[ _]Senior|[ _]Junior)|analyzer|appengine|archiver?|checker|collector|crawl|crawler|(?<!node-|uclient-|Mikrotik/\d\.[x\d] |electron-)fetch(?:er)?|indexer|inspector|monitor|(?<!Microsoft |banshee-)project(?!or)|(?<!Google Wap|Blue )proxy|research|resolver|robots|(?<!Cam)scanner|scraper|script|searcher|(?<!-)security|spider|study|transcoder|uptime|user[ _]?agent|validator)(?:[^a-z]|$)'
  name: 'Generic Bot'

@liviuconcioiu
Copy link
Collaborator

Now, I see why I had a hard time getting the Electron regex working :(.

@sanchezzzhak idea with the updated regexes is great.

@sanchezzzhak
Copy link
Collaborator

@sgiehl can I make the changes suggested above in this branch?

@sgiehl
Copy link
Member Author

sgiehl commented Apr 25, 2024

Feel free to make changes to that branch. I currently haven't time to.
Changing the regex should work. But we could also see if changing the priority here helps:

$this->addClientParser(new FeedReader());
$this->addClientParser(new MobileApp());
$this->addClientParser(new MediaPlayer());
$this->addClientParser(new PIM());
$this->addClientParser(new Browser());
$this->addClientParser(new Library());

sgiehl and others added 3 commits April 29, 2024 10:48
fix: added excludes apps and browsers for bot generic regex
feat(test): improved error output for DeviceDetectorTest::testParseClient method
fix: added exclude SlimerJS prefix for Firefox browser
@sgiehl sgiehl merged commit de9dce9 into master Apr 29, 2024
15 checks passed
@sgiehl sgiehl deleted the overlappingdetections branch April 29, 2024 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants