Skip to content

fix(ui): strip trailing punctuation from URLs in inline markdown#17978

Closed
yuvrajangadsingh wants to merge 1 commit intogoogle-gemini:mainfrom
yuvrajangadsingh:fix/url-trailing-punctuation
Closed

fix(ui): strip trailing punctuation from URLs in inline markdown#17978
yuvrajangadsingh wants to merge 1 commit intogoogle-gemini:mainfrom
yuvrajangadsingh:fix/url-trailing-punctuation

Conversation

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor

@yuvrajangadsingh yuvrajangadsingh commented Jan 30, 2026

Summary

Fixes #16391

URLs in inline markdown include trailing punctuation (periods, commas, CJK fullwidth punctuation like 。,!?) which breaks clickability.

Adds stripTrailingPunctuation() to markdownParsingUtils.ts that strips trailing punctuation from bare URLs while preserving balanced parentheses (for Wikipedia-style URLs like https://en.wikipedia.org/wiki/Foo_(bar)). The stripped punctuation is rendered as plain text after the link.

Reworked from the original approach after InlineMarkdownRenderer.tsx was refactored to use parseMarkdownToANSI.

Test plan

  • npx vitest run packages/cli/src/ui/utils/markdownParsingUtils.test.ts - all 45 tests pass
  • 7 integration tests for parseMarkdownToANSI with trailing punctuation
  • 20 unit tests for stripTrailingPunctuation covering ASCII, CJK, balanced parens, edge cases
  • lint and prettier pass

@yuvrajangadsingh yuvrajangadsingh requested a review from a team as a code owner January 30, 2026 19:10
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @yuvrajangadsingh, 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 resolves an issue where URLs embedded in inline markdown were incorrectly parsed, leading to trailing punctuation being included as part of the clickable link, especially with CJK characters. The changes introduce a new utility function that intelligently strips this trailing punctuation while preserving valid URL structures, such as those containing balanced parentheses. The rendering mechanism is updated to display the corrected, clickable URL and any removed punctuation separately, significantly improving link accuracy and user experience.

Highlights

  • Punctuation Stripping Utility: Implemented a new stripTrailingPunctuation() utility function to intelligently remove extraneous punctuation from the end of URLs, including both ASCII and CJK characters.
  • Balanced Parentheses Preservation: The stripTrailingPunctuation() utility includes logic to preserve balanced parentheses within URLs, crucial for correctly handling links like those found on Wikipedia.
  • Enhanced URL Rendering: The URL rendering logic has been updated to utilize the new utility, ensuring that only the valid URL portion is clickable and any stripped punctuation is displayed separately as plain text.
  • Comprehensive Testing: Added extensive unit tests for the stripTrailingPunctuation() function, covering various scenarios including ASCII and CJK punctuation, no punctuation, balanced parentheses, and unbalanced parentheses.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Copy Markdown
Contributor

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

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 fix for correctly handling trailing punctuation in URLs within inline markdown by creating a dedicated "stripTrailingPunctuation" utility. However, the implementation of "stripTrailingPunctuation" contains a performance flaw that can be exploited to cause a Denial of Service (DoS) due to its O(N^2) complexity with many trailing parentheses. Additionally, the parenthesis-balancing logic has a critical bug as it fails to account for full-width open parentheses, contradicting the goal of supporting CJK characters. This underscores the importance of robust validation and sanitization of user-provided data.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Jan 30, 2026
@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 the stripTrailingPunctuation utility to address issues with trailing punctuation breaking URL navigation. While the comprehensive tests for this utility are commendable, the regular expression used is overly aggressive and may inadvertently strip valid characters that are part of a URL, potentially leading to broken links. This regex needs to be refined to ensure URL correctness.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 effectively addresses the issue of trailing punctuation in URLs within inline markdown. The new stripTrailingPunctuation utility is well-designed, handling various edge cases including balanced parentheses and CJK punctuation, and is accompanied by a comprehensive test suite. The integration into the InlineMarkdownRenderer is also correct. I've identified one high-severity issue related to React's key handling when using fragments in a list, which could lead to warnings or rendering bugs. My detailed comment provides a suggested fix and guidance on choosing stable keys. Overall, this is a great contribution that improves the user experience.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 effectively addresses an issue where trailing punctuation was incorrectly included in URLs within inline markdown. The introduction of the stripTrailingPunctuation utility is a clean solution, and it's well-supported by a comprehensive test suite that covers various edge cases, including CJK punctuation and URLs with parentheses. The changes in the InlineMarkdownRenderer correctly apply this new utility. My review includes one suggestion to improve the performance of the new function by avoiding repeated regular expression compilation.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 effectively fixes an issue where trailing punctuation was incorrectly included in URLs from inline markdown. The introduction of the stripTrailingPunctuation utility is a good approach, and it's well-supported by a comprehensive set of new tests. The core logic for handling balanced parentheses is sound. I have one suggestion to improve the maintainability of the new utility function by making its control flow clearer.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 effectively resolves an issue where trailing punctuation was incorrectly included in URLs within inline markdown. The new stripTrailingPunctuation utility is a well-designed solution, with a robust implementation that correctly handles balanced parentheses in complex URLs. The comprehensive test suite, covering both ASCII and CJK punctuation, provides strong confidence in the fix. The integration into InlineMarkdownRenderer.tsx is clean and correctly separates the URL from trailing characters for rendering. This is a high-quality change that improves URL handling.

@yuvrajangadsingh yuvrajangadsingh requested review from a team as code owners February 4, 2026 15:26
@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 addresses an issue where trailing punctuation was incorrectly included in URLs from inline markdown, which is particularly problematic for CJK languages. The fix introduces a stripTrailingPunctuation utility function that intelligently removes this punctuation while preserving balanced parentheses, a common pattern in Wikipedia URLs. The implementation is supported by a comprehensive set of new unit tests. My review found the changes to be well-implemented. I have one suggestion to improve code clarity in the new utility function by removing redundant characters from a regular expression. Overall, this is a solid fix that improves user experience.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 aims to fix an issue with URLs in inline markdown that incorrectly include trailing punctuation. A new utility function stripTrailingPunctuation is introduced to handle this, along with comprehensive tests. The overall approach is good, but I've found a critical bug in the implementation of the new function where it fails to correctly handle multiple trailing parentheses. I've provided a detailed explanation in the review comments.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 to strip trailing punctuation from auto-detected URLs in markdown, which is a great improvement for user experience, especially with non-ASCII punctuation. No security vulnerabilities were identified in this change. For optimization, consider refining the parenthesis counting logic for better performance on long URLs.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

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

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 effectively addresses the issue of trailing punctuation being incorrectly included in URLs within inline markdown. The stripTrailingPunctuation utility function is well-designed to handle various punctuation types, including CJK characters, and correctly preserves balanced parentheses, which is crucial for URLs like those found on Wikipedia. The comprehensive test suite for this new utility demonstrates a thorough approach to ensuring its correctness. The integration of this utility into the InlineMarkdownRenderer ensures that URLs are displayed accurately without breaking navigation, while still showing the stripped punctuation as plain text. Overall, this is a solid fix that improves the robustness and user experience of URL rendering.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

Hi @NTaylorMullen, this PR is ready for review — all Gemini bot feedback has been addressed and resolved. Would appreciate a look when you get a chance. Thanks!

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/url-trailing-punctuation branch from 2417736 to 53e2b5f Compare February 16, 2026 09:33
@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

Gentle bump — this one's been sitting for a bit. Everything's resolved from the review side, just needs a maintainer approval. Let me know if there's anything else I should address.

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/url-trailing-punctuation branch from 53e2b5f to 86f0a80 Compare February 19, 2026 09:53
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/url-trailing-punctuation branch from 86f0a80 to aeed9c9 Compare February 19, 2026 15:36
@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

Hey @Adib234 — could you take a look at this one too? It's a small fix that strips trailing punctuation (periods, commas, etc.) from URLs in inline markdown so they render as clickable links correctly. All checks pass. Thanks!

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/url-trailing-punctuation branch 4 times, most recently from e71e54a to e5875e7 Compare February 24, 2026 10:20
@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

last bump on this — small fix for trailing punctuation getting included in URLs when rendered as inline markdown. CI green, been open for about a month now. would appreciate a quick look if anyone has a sec.

@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

upstream rewrote InlineMarkdownRenderer.tsx to use parseMarkdownToANSI, so this PR can't rebase cleanly anymore. reworking the fix to fit the new parsing approach now.

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/url-trailing-punctuation branch 2 times, most recently from 3190892 to a6444ef Compare February 28, 2026 22:23
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/url-trailing-punctuation branch from a6444ef to 060a58f Compare March 1, 2026 10:05
@yuvrajangadsingh
Copy link
Copy Markdown
Contributor Author

rework is done, rebased on latest main and everything applies cleanly. the fix now targets parseMarkdownToANSI in markdownParsingUtils.ts since the old InlineMarkdownRenderer was rewritten. CI green, ready for review.

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/url-trailing-punctuation branch 2 times, most recently from eb8839f to 81d4370 Compare March 11, 2026 11:35
Reworked to fit the new parseMarkdownToANSI approach after upstream
refactored InlineMarkdownRenderer.tsx.

Adds stripTrailingPunctuation() to markdownParsingUtils.ts that
strips trailing periods, commas, semicolons etc. from bare URLs
while preserving balanced parentheses (for Wikipedia-style URLs).

Fixes google-gemini#16391
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/url-trailing-punctuation branch from 81d4370 to dbde2c8 Compare March 14, 2026 18:49
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 15, 2026

Hi there! Thank you for your contribution. To keep our backlog manageable, we are closing pull requests that haven't seen maintainer activity for 30 days. If you're still working on this, please let us know!

@gemini-cli gemini-cli bot closed this Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Clickable URLs in inline Markdown include trailing punctuation especially Chinese punctuations, leading to broken navigation

1 participant