-
-
Notifications
You must be signed in to change notification settings - Fork 25
Normalize and encode usernames for LeetPush API requests #137
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,10 @@ export const fetchDailyProblem = async (): Promise<DailyProblemI> => { | |||||
| * @returns The user stats | ||||||
| **/ | ||||||
| export const fetchUserStats = async (username: string): Promise<UserStatsI> => { | ||||||
| const response = await fetch(`${BASE_URL}/${username}`); | ||||||
| const normalizedUsername = username.trim(); | ||||||
| const response = await fetch( | ||||||
| `${BASE_URL}/${encodeURIComponent(normalizedUsername)}`, | ||||||
| ); | ||||||
| if (response.status === 404) throw new Error("User not found"); | ||||||
| else if (!response.ok) throw new Error("Failed to fetch user stats"); | ||||||
|
||||||
| else if (!response.ok) throw new Error("Failed to fetch user stats"); | |
| if (!response.ok) throw new Error("Failed to fetch user stats"); |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as fetchUserStats: username.trim() can yield an empty string, which would hit /userProfileCalendar/ and return an unexpected response. Add a guard for empty normalizedUsername before calling fetch().
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The username normalization/encoding logic is duplicated in both fetchUserStats and fetchUserStreak. Consider extracting a small helper (e.g. normalizeUsernameForPath) so future changes (like additional normalization rules) only need to be made in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After trimming,
normalizedUsernamecan become an empty string (e.g. user enters only whitespace). In that case this will call${BASE_URL}/(wrong endpoint) and likely produce confusing errors. Consider validatingnormalizedUsernameaftertrim()and throwing a user-facing error before issuing the request.