Repository navigation
Conversation
generate() accepted browser_type but built the browser stack with random.choice over every browser, so a firefox request could return a Chrome or Edge user agent while the legacy token branch already assumed the requested browser. Pick the version from the requested browser's list and keep the random stack only when no type is requested. Fixes unclecode#2566.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
UserAgentGenerator.generate(browser_type=...)builds the browser stack withget_browser_stack(num_browsers), which picks each browser at random.generate(browser_type='firefox')can therefore return a Chrome or Edge user agent, and the legacy token branch already keys off the requested type, so the result is internally inconsistent.Fix
When
browser_typeis set, choose one version from that browser's list (the same listsget_browser_stack()uses) instead of a random stack. Without a requested type, the previous random behaviour is unchanged.Tests
tests/test_user_agent_browser_type.pystubsget_browser_stack()to return a Chrome stack and asserts thatfirefoxandedgerequests still produce Firefox/Edge user agents without Chrome/Edg leakage.python -m pytest tests/test_user_agent_browser_type.py -q: 2 passed.python -m py_compileclean; no browser or network needed.Fixes #2566.