Skip to content

Conversation

@KTibow
Copy link
Contributor

@KTibow KTibow commented Aug 26, 2025

Please describe the changes this PR makes and why it should be merged:
The underscore matcher already has (?<!<a?:.+|https?:\/\/\S+), which prevents escaping underscores in emojis, animated emojis, and links (from the https to the first whitespace character).
This PR makes sure asterisks aren't escaped in links either. Fixes #11063.

Status and versioning classification:

  • Code changes but no Discord API related changes
  • Typings don't need updating

@vercel
Copy link

vercel bot commented Aug 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
discord-js Ignored Ignored Preview Nov 9, 2025 8:56am
discord-js-guide Ignored Ignored Preview Nov 9, 2025 8:56am

Copy link
Member

@Jiralite Jiralite left a comment

Choose a reason for hiding this comment

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

Please add a test or tests for this!

@github-project-automation github-project-automation bot moved this from Todo to Review in Progress in discord.js Aug 26, 2025
@codecov
Copy link

codecov bot commented Aug 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.27%. Comparing base (3cb3eca) to head (4c5d68f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11064      +/-   ##
==========================================
- Coverage   44.39%   44.27%   -0.13%     
==========================================
  Files         315      310       -5     
  Lines       18134    17659     -475     
  Branches     1805     1758      -47     
==========================================
- Hits         8051     7818     -233     
+ Misses      10071     9829     -242     
  Partials       12       12              
Flag Coverage Δ
formatters 99.67% <100.00%> (+<0.01%) ⬆️
structures 85.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KTibow
Copy link
Contributor Author

KTibow commented Aug 26, 2025

Added

Edit: I forgot to test locally, give me a moment to set up my env

@almeidx almeidx changed the title fix(formatters): don't escape * in links fix: don't escape asterisks in links Aug 26, 2025
@KTibow
Copy link
Contributor Author

KTibow commented Aug 26, 2025

Patched

@Jiralite Jiralite dismissed their stale review August 26, 2025 23:13

Resolved.

@Jiralite Jiralite self-requested a review August 26, 2025 23:13
@Qjuh
Copy link
Member

Qjuh commented Aug 29, 2025

This fixes that but opens another can of worms (which also is an issue with underscore formatter then). The following markdown <http://*.example.com/globber/*>*Hi* is valid and renders as
IMG_6871
But because there is no space between the > and the * your PR would escape it to not be italic Hi anymore.

@KTibow
Copy link
Contributor Author

KTibow commented Aug 29, 2025

But because there is no space between the > and the * your PR would escape it to not be italic Hi anymore.

Do you mean that this PR would fail to escape the italics, introducing new problematic behavior? That's fair, I'll see what I can do about that.

@KTibow KTibow changed the title fix: don't escape asterisks in links fix: improve handling of italics in the presence of links Aug 29, 2025
@almeidx almeidx requested a review from Copilot November 8, 2025 17:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the escapeItalic function to better handle URLs containing asterisks and underscores. The regex patterns are updated to avoid escaping italic markdown characters (single asterisks and underscores) that appear within URLs, while still properly escaping them after angle-bracketed URLs.

Key changes:

  • Updated regex patterns in escapeItalic to add negative lookbehinds that detect URLs and prevent escaping of * and _ characters within them
  • Added support for both plain URLs and angle-bracketed URLs (<https://...>)
  • Added test cases for URLs containing asterisks (wildcards/globs) and verification that characters after angle-bracketed URLs are still properly escaped

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/formatters/src/escapers.ts Enhanced regex patterns in escapeItalic with nested negative lookbehinds to detect and skip URL patterns when escaping italic markdown characters
packages/formatters/tests/escapers.test.ts Added test URLs with asterisks and new test case verifying that italic characters after angle-bracketed URLs are properly escaped

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@almeidx almeidx requested a review from Qjuh November 8, 2025 21:15
@github-project-automation github-project-automation bot moved this from Review in Progress to Review Approved in discord.js Nov 9, 2025
@kodiakhq kodiakhq bot merged commit 9723cc5 into discordjs:main Nov 9, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from Review Approved to Done in discord.js Nov 9, 2025
Jiralite pushed a commit that referenced this pull request Nov 9, 2025
* fix(formatters): don't escape * in links

* add test for * -> * in url

* `\S+` -> `\S*` (tested locally)

* @Qjuh: handle italics both inside+outside <url>s

* more accurate <link> matcher

---------

Co-authored-by: Qjuh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Italics shouldn't be escaped in links

5 participants