d
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import Any, Dict, List, Sequence, Optional, Set, Tuple
|
||||
import sys
|
||||
import re
|
||||
from fnmatch import fnmatch
|
||||
from urllib.parse import urlparse
|
||||
from urllib.parse import urlparse, parse_qsl, urlencode, urlunparse
|
||||
from . import _shared as sh
|
||||
|
||||
Cmdlet, SharedArgs, parse_cmdlet_args, get_field, normalize_hash = (
|
||||
@@ -67,6 +67,35 @@ class Get_Url(Cmdlet):
|
||||
"""
|
||||
url = str(url or "").strip()
|
||||
|
||||
# Strip fragment (e.g., #t=10) before matching
|
||||
url = url.split("#", 1)[0]
|
||||
|
||||
# Strip common time/tracking query params for matching
|
||||
try:
|
||||
parsed = urlparse(url)
|
||||
except Exception:
|
||||
parsed = None
|
||||
|
||||
if parsed is not None and parsed.query:
|
||||
time_keys = {"t", "start", "time_continue", "timestamp", "time", "begin"}
|
||||
tracking_prefixes = ("utm_",)
|
||||
try:
|
||||
pairs = parse_qsl(parsed.query, keep_blank_values=True)
|
||||
filtered = []
|
||||
for key, val in pairs:
|
||||
key_norm = str(key or "").lower()
|
||||
if key_norm in time_keys:
|
||||
continue
|
||||
if key_norm.startswith(tracking_prefixes):
|
||||
continue
|
||||
filtered.append((key, val))
|
||||
if filtered:
|
||||
url = urlunparse(parsed._replace(query=urlencode(filtered, doseq=True)))
|
||||
else:
|
||||
url = urlunparse(parsed._replace(query=""))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Remove protocol (http://, https://, ftp://, etc.)
|
||||
url = re.sub(r"^[a-z][a-z0-9+.-]*://", "", url, flags=re.IGNORECASE)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user