Skip to content

Commit 7734d97

Browse files
committed
Add username validation
Fixes #1317
1 parent a62ec9c commit 7734d97

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/routes/timeline.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ proc createTimelineRouter*(cfg: Config) =
114114
get "/@name/?@tab?/?":
115115
cond '.' notin @"name"
116116
cond @"name" notin ["pic", "gif", "video", "search", "settings", "login", "intent", "i"]
117+
cond @"name".allCharsInSet({'a'..'z', 'A'..'Z', '0'..'9', '_'})
117118
cond @"tab" in ["with_replies", "media", "search", ""]
118119
let
119120
prefs = cookiePrefs()

tests/test_profile.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515
['Poop', 'Randy', 'Social media fanatic.']
1616
]
1717

18-
invalid = [['thisprofiledoesntexist'], ['%']]
18+
invalid = [['thisprofiledoesntexist']]
19+
20+
malformed = [
21+
['${userId}'],
22+
['$%7BuserId%7D'], # URL encoded version
23+
['%'], # Percent sign is invalid
24+
['user@name'],
25+
['user.name'],
26+
['user-name'],
27+
['user$name'],
28+
['user{name}'],
29+
['user name'], # space
30+
]
1931

2032
banner_image = [
2133
['mobile_test', 'profile_banners%2F82135242%2F1384108037%2F1500x500']
@@ -65,6 +77,13 @@ def test_invalid_username(self, username):
6577
self.open_nitter(username)
6678
self.assert_text(f'User "{username}" not found')
6779

80+
@parameterized.expand(malformed)
81+
def test_malformed_username(self, username):
82+
"""Test that malformed usernames (with invalid characters) return 404"""
83+
self.open_nitter(username)
84+
# Malformed usernames should return 404 page not found, not try to fetch from Twitter
85+
self.assert_text('Page not found')
86+
6887
def test_suspended(self):
6988
self.open_nitter('suspendme')
7089
self.assert_text('User "suspendme" has been suspended')

0 commit comments

Comments
 (0)