Skip to content

fix: align no-reversed-media-syntax masking with UTF-16 offsets#640

Merged
lumirlumir merged 1 commit intomainfrom
fix/no-reversed-media-syntax-utf16-offsets
Mar 30, 2026
Merged

fix: align no-reversed-media-syntax masking with UTF-16 offsets#640
lumirlumir merged 1 commit intomainfrom
fix/no-reversed-media-syntax-utf16-offsets

Conversation

@Pixel998
Copy link
Copy Markdown
Contributor

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?

This PR fixes no-reversed-media-syntax so it handles text containing characters represented by surrogate pairs correctly. The rule was building its masking buffer by Unicode code points while using source offsets in UTF-16 code units, which could misalign masking and lead to incorrect internal scanning on inputs with emoji-like characters.

What changes did you make? (Give an overview)

  • Updated no-reversed-media-syntax to build its masking buffer with UTF-16 code units by replacing Array.from(sourceCode.getText(node)) with sourceCode.getText(node).split("").
  • Added regression tests

Related Issues

Fixes #639

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

@eslintbot eslintbot added this to Triage Mar 28, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Mar 28, 2026
@lumirlumir lumirlumir self-requested a review March 28, 2026 15:14
@Pixel998 Pixel998 moved this from Needs Triage to Implementing in Triage Mar 30, 2026
@lumirlumir lumirlumir moved this from Implementing to Needs Triage in Triage Mar 30, 2026
@lumirlumir lumirlumir moved this from Needs Triage to Triaging in Triage Mar 30, 2026
@lumirlumir lumirlumir requested a review from Copilot March 30, 2026 15:21
Copy link
Copy Markdown

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

Fixes no-reversed-media-syntax masking so it stays aligned with ESLint/JS UTF-16 source offsets when the markdown contains surrogate-pair characters (e.g., emoji), preventing incorrect scanning/masking behavior.

Changes:

  • Build the rule’s masking buffer using UTF-16 code units (split("")) instead of Unicode code points (Array.from(...)).
  • Add regression tests covering valid/invalid cases with surrogate-pair characters before reversed syntax.

Reviewed changes

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

File Description
src/rules/no-reversed-media-syntax.js Switch masking buffer construction to UTF-16 code units to match getRange/offset indexing.
tests/rules/no-reversed-media-syntax.test.js Add emoji-based regression tests to validate correct detection and fix ranges with surrogate pairs.

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

Copy link
Copy Markdown
Member

@lumirlumir lumirlumir left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Indeed, Array.from treats emojis as a single character, so the following problem arises:

console.log(Array.from("🎉"), "🎉".length); // [ '�' ] 2
console.log("🎉".split(""), "🎉".length); // [ '\ud83c', '\udf89' ] 2

Just for reference, a similar issue occurred in #551 regarding handling code units.

@lumirlumir lumirlumir merged commit 7111e25 into main Mar 30, 2026
39 checks passed
@lumirlumir lumirlumir deleted the fix/no-reversed-media-syntax-utf16-offsets branch March 30, 2026 15:33
@github-project-automation github-project-automation Bot moved this from Triaging to Complete in Triage Mar 30, 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.

Bug: linting stalls on README after v8 update

4 participants