-
Notifications
You must be signed in to change notification settings - Fork 14.2k
fix(core): strip trailing periods from error URLs #28069
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -33,10 +33,16 @@ export function isAbortError(error: unknown): boolean { | |||||
| return error instanceof Error && error.name === 'AbortError'; | ||||||
| } | ||||||
|
|
||||||
| function stripTrailingPeriodsFromUrls( | ||||||
| message: string | null | undefined, | ||||||
| ): string { | ||||||
| return message?.replace(/(https?:\/\/\S+)\.(?=\s|$)/g, '$1') ?? ''; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current regular expression Because We can make the regex more robust by:
This ensures that periods outside parentheses are preserved (without swallowing the parenthesis), and periods inside parentheses are correctly stripped.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| export function getErrorMessage(error: unknown): string { | ||||||
| const friendlyError = toFriendlyError(error); | ||||||
| if (friendlyError instanceof Error) { | ||||||
| return friendlyError.message; | ||||||
| return stripTrailingPeriodsFromUrls(friendlyError.message); | ||||||
| } | ||||||
| if ( | ||||||
| typeof friendlyError === 'object' && | ||||||
|
|
@@ -45,10 +51,11 @@ export function getErrorMessage(error: unknown): string { | |||||
| typeof (friendlyError as { message: unknown }).message === 'string' | ||||||
| ) { | ||||||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||||||
| return (friendlyError as { message: string }).message; | ||||||
| const message = (friendlyError as { message: string }).message; | ||||||
| return stripTrailingPeriodsFromUrls(message); | ||||||
| } | ||||||
| try { | ||||||
| return String(friendlyError); | ||||||
| return stripTrailingPeriodsFromUrls(String(friendlyError)); | ||||||
| } catch { | ||||||
| return 'Failed to get error details'; | ||||||
| } | ||||||
|
|
||||||
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.
Add comprehensive test cases to verify the behavior of URLs wrapped in parentheses or brackets (both with periods inside and outside the brackets/parentheses) to ensure the regex handles these edge cases correctly and doesn't swallow closing brackets.