Skip to content

fix: escaped parentheses in nested labels in no-reversed-media-syntax - #752

Merged
DMartens merged 2 commits into
mainfrom
fix/escaped-parentheses-in-nested-labels-in-no-reversed-media-syntax
Oct 23, 2026
Merged

DMartens merged 2 commits into
mainfrom
fix/escaped-parentheses-in-nested-labels-in-no-reversed-media-syntax

Conversation

@lumirlumir

@lumirlumir lumirlumir commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

Environment

  • ESLint: 10.9.1
  • @eslint/markdown: 8.0.3
  • Node: 24.18.0
  • npm: 12.2.0
  • OS: Windows

Which language are you using?

commonmark and gfm

What did you do?

Linted the following Markdown:

<!-- eslint markdown/no-reversed-media-syntax: "error" -->

(a (b \(c\)) d)[x]

What did you expect to happen?

The rule should report reversed syntax and autofix it to:

<!-- eslint markdown/no-reversed-media-syntax: "error" -->

[a (b \(c\)) d](x)

What actually happened?

No problems were reported.

What changes did you make? (Give an overview)

Fixes a regression introduced in #693 that was overlooked during review. I found it while reviewing #736 (comment), thanks to a comment from CodeRabbit.

The limitation introduced in #693 was that parentheses nested two or more levels deep were no longer reported. However, escaped parentheses should still be reported because they don’t create nested parentheses.

I’ve looked into this carefully, and this change does not introduce any ReDoS-related regressions. The newly added [\s\S] pattern does not cause catastrophic time complexity.

Related Issues

#693

Is there anything you'd like reviewers to focus on?

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Improved detection of reversed Markdown links and images when labels contain nested parentheses or escaped characters, including escaped newlines and backslashes.
    • Corrected handling of unmatched outer parentheses in these constructs.
    • Error reporting continues to identify the full original construct and provide accurate diagnostic locations.

@eslint-github-bot eslint-github-bot Bot added the bug label Oct 8, 2026
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack β†’

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration
  • Configuration used: Repository: eslint/coderabbit/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ec032a47-aa8f-487c-962c-95b393f18389
πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 507ff28 and b5b7b1d.

πŸ“’ Files selected for processing: 1
  • tests/rules/no-reversed-media-syntax.test.js

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

πŸ“ Walkthrough

The reversed media pattern now supports nested parentheses and escaped characters in labels. Tests cover reversed links and images with these label forms and verify conversion and error ranges.

Changes: Reversed media syntax

Layer / File(s) Summary
Pattern and label coverage
src/rules/no-reversed-media-syntax.js, tests/rules/no-reversed-media-syntax.test.js
The pattern supports nested parentheses and escaped characters in labels while retaining its non-overlap constraint. Tests cover reversed links and images with escaped delimiters, backslash runs, and backslash-newline sequences. They verify the converted syntax and reversedSyntax error ranges.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: βšͺ Minimal Β· up to b5b7b

The change is mergeable with no established correctness, security, or availability risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: fixing escaped parentheses in nested labels for the no-reversed-media-syntax rule.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
πŸ“ Generate docstrings
  • Commit to this branch
  • Create a new PR
πŸ§ͺ Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot Β· Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@eslintbot eslintbot added this to Triage Oct 8, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Oct 8, 2026
@lumirlumir
lumirlumir marked this pull request as ready for review October 8, 2026 12:02
@github-actions

Copy link
Copy Markdown
Contributor

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions Bot added the Stale label Oct 18, 2026
@DMartens DMartens removed the Stale label Oct 19, 2026
DMartens
DMartens previously approved these changes Oct 19, 2026

@DMartens DMartens 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.

Changes LGTM, thanks.
Only a suggestion to add an additional test case to catch regressions in the future.

* The nested group is `\((?:\\[\s\S]|[^()\\])*\)`, not `\([\s\S]*\)`, so that it cannot overlap the
* other alternatives. Overlapping alternatives cause catastrophic backtracking.
*/
const reversedPattern =

@DMartens DMartens Oct 19, 2026 •

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.

The current regular expression does not match:
(a (b (c\)) d)[x] (removed the first escaping backslash before c)

But the updated version now matches (b (c\)) d)[x] (without (a at the beginning, regex101).
I am unsure how we should handle this / if this is even a bug.
It would be good to add this as a test case, so we can catch regressions if we change the regular expression in the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. After looking into this, it seems consistent with how CommonMark handles regular links: [a [b [c\]] d](x) recognizes only [b [c\]] d](x) as a link, leaving [a as text. So I am not sure this is a bug in this case.

References: link parsing algorithm and Code Explorer.

To clarify:

  • (c\)) is one matching pair of parentheses.
  • (b (c\)) d) is another matching pair of parentheses.
  • So (a is left unmatched and ignored in this case.

I’ve also updated the test cases in b5b7b1d.

@DMartens DMartens moved this from Needs Triage to Merge Candidates in Triage Oct 19, 2026

@DMartens DMartens 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.

Changes LGTM, thanks.

@DMartens
DMartens merged commit 502ddd9 into main Oct 23, 2026
40 checks passed
@DMartens
DMartens deleted the fix/escaped-parentheses-in-nested-labels-in-no-reversed-media-syntax branch October 23, 2026 20:44
@github-project-automation github-project-automation Bot moved this from Merge Candidates to Complete in Triage Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants