fix(reddit): use removeprefix("r/") for subreddit names, not lstrip("r/")

str.lstrip("r/") treats its argument as a character set, stripping
leading r and / repeatedly. Subreddits starting with 'r' (e.g. r/robotics,
r/ruby) were silently mangled to 'obotics' / 'uby'. Replace with
str.removeprefix("r/") at all four call sites. Python 3.9+ pattern is
safe here — project requires 3.12. Closes #288.

Co-authored-by: Alex Key <alexanderkey0508@gmail.com>
This commit is contained in:
Trevin Chow
2026-05-17 01:28:46 -07:00
parent bb5e6efbf9
commit 5994b4f76a
3 changed files with 4 additions and 4 deletions
@@ -198,7 +198,7 @@ def search(
encoded_query = _url_encode(query)
if subreddit:
sub = subreddit.lstrip("r/").strip()
sub = subreddit.removeprefix("r/").strip()
url = (
f"https://www.reddit.com/r/{sub}/search.json"
f"?q={encoded_query}&restrict_sr=on&sort=relevance&t=month&limit={limit}&raw_json=1"