Skip to content

🐛(frontend) sanitize pasted toolbar links#2214

Open
Ovgodd wants to merge 2 commits intomainfrom
fix/link-paste-angle-brackets
Open

🐛(frontend) sanitize pasted toolbar links#2214
Ovgodd wants to merge 2 commits intomainfrom
fix/link-paste-angle-brackets

Conversation

@Ovgodd
Copy link
Copy Markdown
Collaborator

@Ovgodd Ovgodd commented Apr 15, 2026

Purpose

Fix broken links when pasting a URL into the BlockNote link toolbar input.
BlockNote copies links in Markdown autolink format (<url>), and the angle
brackets are kept as-is when pasting, resulting of invalid hrefs.

lien.mp4

Proposal

  • Add a onPasteCapture handler that strips <> from pasted URLs in
    input/textarea fields within the editor container

@Ovgodd Ovgodd requested a review from AntoLC April 15, 2026 07:58
@Ovgodd Ovgodd self-assigned this Apr 15, 2026
@Ovgodd Ovgodd added the bug Something isn't working label Apr 15, 2026
Strip < and > from pasted BlockNote links to keep valid external URLs.
@Ovgodd Ovgodd force-pushed the fix/link-paste-angle-brackets branch from b6777f9 to 598a6ad Compare April 15, 2026 08:00
@Ovgodd Ovgodd marked this pull request as ready for review April 15, 2026 08:00
@Ovgodd Ovgodd linked an issue Apr 15, 2026 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 15, 2026

Size Change: 0 B

Total Size: 4.26 MB

📦 View Changed
Filename Size Change
apps/impress/out/_next/static/54175c6e/_buildManifest.js 637 B +637 B (new file) 🆕
apps/impress/out/_next/static/68656906/_buildManifest.js 0 B -637 B (removed) 🏆

compressed-size-action

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

Walkthrough

The PR updates CHANGELOG.md with a new "[Unreleased] → Fixed" entry for sanitizing pasted toolbar links and minor formatting tweaks to existing bullets. In the frontend, BlockNoteEditor gains an onPasteCapture handler that, when pasting into input or textarea elements, reads plain-text clipboard data, removes a single pair of surrounding angle brackets if present, prevents the default paste, replaces the selected/input range using setRangeText, and dispatches a bubbling input event.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: sanitizing pasted toolbar links in the frontend to fix broken links caused by angle brackets.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description clearly describes the issue (broken links when pasting URLs with angle brackets) and the proposed solution (strip angle brackets from pasted content).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/link-paste-angle-brackets

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx (1)

99-106: Scope this paste sanitizer to the link toolbar field only.

Because capture is attached at Line 302 on the editor root, any nested input/textarea can be affected. Consider guarding by a specific attribute/class for the link URL input to avoid side effects in unrelated controls.

Also applies to: 302-302

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx`:
- Around line 112-120: The paste handler currently replaces the entire
input/textarea value with the sanitized text; instead, read the element's
existing value and selection (use target.selectionStart and target.selectionEnd
on HTMLInputElement/HTMLTextAreaElement), construct a newValue by inserting the
cleaned text between those indices, use the native value setter (as you already
get from Object.getOwnPropertyDescriptor(proto, 'value')?.set) to set newValue,
then restore/update the caret/selection to sit after the inserted text (set
selectionStart/selectionEnd to start + cleaned.length) before dispatching the
input event; apply these changes in the paste handling logic inside
BlockNoteEditor so surrounding content is preserved and caret semantics are
correct.
- Around line 107-111: The code trims pasted text before stripping angle
brackets which causes unchanged content with leading/trailing spaces to be
rewritten; in BlockNoteEditor replace const cleaned =
stripAngleBrackets(text.trim()) with const cleaned = stripAngleBrackets(text) so
you do not remove whitespace when there are no angle brackets, and keep the
existing comparison if (cleaned === text) return; (handle any trimming later
only when you actually need normalized content).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5db157d4-5c20-4ac3-a869-bfd13f71fd67

📥 Commits

Reviewing files that changed from the base of the PR and between 9a5d81f and 598a6ad.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx

@Ovgodd Ovgodd moved this to In Progress in LaSuite Docs Apr 15, 2026
Copy link
Copy Markdown
Collaborator

@AntoLC AntoLC left a comment

Choose a reason for hiding this comment

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

I think we should open a issue on Blocknote because it is a problem on their side at the base.

I am not huge fan of the patch, because we fix the symptom (paste), but not the root cause (copy), if you paste the link somewhere else (e.g: in the browser url input) you still have the problem.
Plus we are now overriding the paste event, even if it is targeting only the input, it could bring unexpected side effects that we will have to support.

The problem comes probably from this file, I suggest we either open a issue, or propose a fix on their side:
https://github.com/TypeCellOS/BlockNote/blob/main/packages/core/src/api/clipboard/toClipboard/copyExtension.ts#L176-L199


We could eventually merge this PR in waiting for the fix on the BN side, but we should let the issue opened until Blocknote made the fix, and then remove the patch.


Wdyt ?

@Ovgodd
Copy link
Copy Markdown
Collaborator Author

Ovgodd commented Apr 20, 2026

I think we should open a issue on Blocknote because it is a problem on their side at the base.

I am not huge fan of the patch, because we fix the symptom (paste), but not the root cause (copy), if you paste the link somewhere else (e.g: in the browser url input) you still have the problem. Plus we are now overriding the paste event, even if it is targeting only the input, it could bring unexpected side effects that we will have to support.

The problem comes probably from this file, I suggest we either open a issue, or propose a fix on their side: https://github.com/TypeCellOS/BlockNote/blob/main/packages/core/src/api/clipboard/toClipboard/copyExtension.ts#L176-L199

We could eventually merge this PR in waiting for the fix on the BN side, but we should let the issue opened until Blocknote made the fix, and then remove the patch.

Wdyt ?

Yes, I agree, we need to handle the root case. I’m ok with merging this for now, and I’ll create a PR on the BlockNote side.

EDI : pr on BN side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Copying a url includes the formatting characters

2 participants