Skip to content

fix(core): strip trailing periods from error URLs#28069

Closed
aniruddhaadak80 wants to merge 1 commit into
google-gemini:mainfrom
aniruddhaadak80:fix/errors-trailing-period-url
Closed

fix(core): strip trailing periods from error URLs#28069
aniruddhaadak80 wants to merge 1 commit into
google-gemini:mainfrom
aniruddhaadak80:fix/errors-trailing-period-url

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

Closes #28052

@aniruddhaadak80 aniruddhaadak80 requested a review from a team as a code owner June 21, 2026 05:30
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where URLs included in error messages were incorrectly terminated with a trailing period, rendering them invalid. The changes implement a regex-based utility to detect and clean these URLs while ensuring that standard sentence-ending periods remain unaffected.

Highlights

  • URL Sanitization: Introduced a utility function to strip trailing periods from URLs within error messages to prevent broken links.
  • Error Handling Update: Updated the getErrorMessage function to apply the new URL sanitization logic across all error message return paths.
  • Test Coverage: Added comprehensive test cases to verify URL period stripping and ensure normal punctuation is preserved.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the size/s A small PR label Jun 21, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 37
  • Additions: +34
  • Deletions: -3
  • Files changed: 2

@github-actions

Copy link
Copy Markdown

You already have 7 pull requests open. Please work on getting existing PRs merged before opening more.

@github-actions github-actions Bot closed this Jun 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a utility function stripTrailingPeriodsFromUrls to remove trailing periods from URLs in error messages, and applies it within getErrorMessage. It also adds corresponding unit tests. The review feedback highlights a correctness issue with the regular expression when URLs are wrapped in parentheses or brackets, which can cause closing brackets to be swallowed or periods inside parentheses to be missed. It suggests a more robust regex and additional test cases to cover these edge cases.

function stripTrailingPeriodsFromUrls(
message: string | null | undefined,
): string {
return message?.replace(/(https?:\/\/\S+)\.(?=\s|$)/g, '$1') ?? '';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current regular expression /(https?:\/\/\S+)\.(?=\s|$)/g has a correctness issue when URLs are wrapped in parentheses or brackets, such as (https://google.com). or [https://google.com]..

Because \S+ is greedy and matches closing brackets/parentheses, it will swallow the closing parenthesis/bracket into the URL group $1 and strip the trailing period, resulting in "Go to (https://google.com)" (where the URL now incorrectly ends with a parenthesis). Conversely, for a URL like (https://google.com.) where the period is inside the parenthesis, the regex fails to match because the period is followed by ) (which is not whitespace or end of string).

We can make the regex more robust by:

  1. Excluding closing brackets/parentheses from the URL match group using [^\s)\]}]+.
  2. Allowing optional closing brackets/parentheses in the lookahead assertion: (?=[)\]}]?(?:\s|$)).

This ensures that periods outside parentheses are preserved (without swallowing the parenthesis), and periods inside parentheses are correctly stripped.

Suggested change
return message?.replace(/(https?:\/\/\S+)\.(?=\s|$)/g, '$1') ?? '';
return message?.replace(/(https?:\/\/[^\s)\]}]+)\.(?=[)\]}]?(?:\s|$))/g, '$1') ?? '';

Comment on lines +51 to +63
it('should remove a trailing period from URLs in error messages', () => {
const error = new Error('Migrate to https://antigravity.google.');

expect(getErrorMessage(error)).toBe(
'Migrate to https://antigravity.google',
);
});

it('should preserve periods that do not trail a URL', () => {
expect(getErrorMessage(new Error('Authentication failed.'))).toBe(
'Authentication failed.',
);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

  it('should remove a trailing period from URLs in error messages', () => {
    const error = new Error('Migrate to https://antigravity.google.');

    expect(getErrorMessage(error)).toBe(
      'Migrate to https://antigravity.google',
    );
  });

  it('should handle URLs wrapped in parentheses or brackets correctly', () => {
    expect(getErrorMessage(new Error('Go to (https://google.com.)'))).toBe(
      'Go to (https://google.com)',
    );
    expect(getErrorMessage(new Error('Go to (https://google.com).'))).toBe(
      'Go to (https://google.com).',
    );
    expect(getErrorMessage(new Error('Go to [https://google.com.]'))).toBe(
      'Go to [https://google.com]',
    );
    expect(getErrorMessage(new Error('Go to [https://google.com].'))).toBe(
      'Go to [https://google.com].',
    );
  });

  it('should preserve periods that do not trail a URL', () => {
    expect(getErrorMessage(new Error('Authentication failed.'))).toBe(
      'Authentication failed.',
    );
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Trailing '.' in antigravity.google URL in error message causes link to not load

1 participant