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

Strip user-agent whitespaces and ignore empty user agents #310

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/zimit/zimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,16 @@
"logging",
]:
value = getattr(args, arg)
if arg == "userAgent":
# - strip leading whitespace which are not allowed on some websites
# - strip trailing whitespace which are either not allowed if no suffix is
# used, or duplicate with the automatically added one if a suffix is there
# - value is None when userAgent is not passed
if value:
value = value.strip()

Check warning on line 567 in src/zimit/zimit.py

View check run for this annotation

Codecov / codecov/patch

src/zimit/zimit.py#L567

Added line #L567 was not covered by tests
if not value:
# ignore empty userAgent arg and keep crawler default value if empty
continue

Check warning on line 570 in src/zimit/zimit.py

View check run for this annotation

Codecov / codecov/patch

src/zimit/zimit.py#L570

Added line #L570 was not covered by tests
if value is None or (isinstance(value, bool) and value is False):
continue
node_cmd.append("--" + arg)
Expand Down