fix(link): reject shebang lines in validateUrl to prevent autolinking (#5039) - #5077
Closed
Samarth1306w wants to merge 1 commit into
Closed
Conversation
…#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
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
🦋 Changeset detectedLatest commit: f79a826 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 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/shor#!/usr/bin/env node) was pasted into an editor withLinkPluginenabled,validateUrlcheckedurl.startsWith('#')and treated it as an anchor link URL. Because it returnedtruebefore checkingisUrl, plain text shell scripts were misdetected and wrapped into a single link node.🛠️ Surgical Patch Breakdown
packages/link/src/lib/utils/validateUrl.ts:Added
SHEBANG_PATTERN = /^#!(/.*)?$/. InvalidateUrl, reject shebang lines starting with#!so they are not misdetected as valid anchor links.packages/link/src/lib/utils/validateUrl.spec.ts:Added unit tests verifying
validateUrlrejects shebang lines starting with#!..changeset/fix-link-plugin-autolink-shebang.md: Added patch changeset for@platejs/link.🧪 Verification & Test Coverage
packages/link/src/lib/utils/validateUrl.spec.tsverify shebang lines (#!/bin/sh,#!/usr/bin/env node) returnfalse.@platejs/link.mainwith 0 conflicts.