Skip to content

fix(link): reject shebang lines in validateUrl to prevent autolinking (#5039) - #5077

Closed
Samarth1306w wants to merge 1 commit into
udecode:mainfrom
Samarth1306w:fix/link-plugin-autolink-shebang-paths-5039
Closed

fix(link): reject shebang lines in validateUrl to prevent autolinking (#5039)#5077
Samarth1306w wants to merge 1 commit into
udecode:mainfrom
Samarth1306w:fix/link-plugin-autolink-shebang-paths-5039

Conversation

@Samarth1306w

@Samarth1306w Samarth1306w commented Aug 5, 2026

Copy link
Copy Markdown
  • Auto release

🎯 Summary

Fixes #5039 — LinkPlugin autolinks pasted plain text starting with "#" or "/" (e.g. shebang "#!/bin/sh").

🔍 Root Cause Analysis

When plain text starting with a shebang (e.g. #!/bin/sh or #!/usr/bin/env node) was pasted into an editor with LinkPlugin enabled, validateUrl checked url.startsWith('#') and treated it as an anchor link URL. Because it returned true before checking isUrl, plain text shell scripts were misdetected and wrapped into a single link node.

🛠️ Surgical Patch Breakdown

  1. packages/link/src/lib/utils/validateUrl.ts:
    Added SHEBANG_PATTERN = /^#!(/.*)?$/. In validateUrl, reject shebang lines starting with #! so they are not misdetected as valid anchor links.
  2. packages/link/src/lib/utils/validateUrl.spec.ts:
    Added unit tests verifying validateUrl rejects shebang lines starting with #!.
  3. .changeset/fix-link-plugin-autolink-shebang.md: Added patch changeset for @platejs/link.

🧪 Verification & Test Coverage

  • Automated Unit Tests: Unit tests in packages/link/src/lib/utils/validateUrl.spec.ts verify shebang lines (#!/bin/sh, #!/usr/bin/env node) return false.
  • Changeset Included: Patch changeset generated for @platejs/link.
  • Clean Merge: Branch rebased cleanly against main with 0 conflicts.

…#5039)

When plain text starting with a shebang (e.g. #!/bin/sh) was pasted,
validateUrl checked url.startsWith('#') and treated it as an anchor link URL,
wrapping the plain text shell script into a link node.

Fix:
- Reject shebang lines starting with #! in validateUrl.
- Add unit test coverage verifying shebang lines are rejected by validateUrl.
- Add patch changeset for @platejs/link.

Closes #5039
@codesandbox

codesandbox Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f79a826

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@platejs/link Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working patch Bugfix & documentation PR plugin:link labels Aug 5, 2026
@zbeyens zbeyens closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Bugfix & documentation PR plugin:link size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LinkPlugin autolinks pasted plain text starting with "#" or "/" (e.g. shebang "#!/bin/sh")

3 participants