Repository navigation
[INFRA-1223] fix: open editor links from the anchor only - #10308
Conversation
…ved URL The link click handler now resolves the anchor that contains the click target, uses only that anchor's browser-resolved href (never the mark attribute from the editor state), applies the shared dangerous-scheme check, and opens with noopener,noreferrer, honouring only _blank and _self as targets.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 28 minutes. View limit details
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. |
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
|
Linked to Plane Work Item(s) This comment was auto-generated by Plane |
sriramveeraghanta
left a comment
There was a problem hiding this comment.
LGTM. closest("a") plus the view.dom.contains check handles links inside marks and ignores outer anchors. Still worth the manual browser check (tab vs popup) the description asks for.
The link click handler now resolves the anchor that contains the click target, uses only that anchor's browser-resolved href (never the mark attribute from the editor state), applies the shared dangerous-scheme check, and opens with noopener,noreferrer, honouring only _blank and _self as targets.
…0308) The link click handler now resolves the anchor that contains the click target, uses only that anchor's browser-resolved href (never the mark attribute from the editor state), applies the shared dangerous-scheme check, and opens with noopener,noreferrer, honouring only _blank and _self as targets. (cherry picked from commit d375d6d)
The handler resolves the clicked anchor with closest("a") and opens with
noopener,noreferrer (ported makeplane#10308); the test now builds that event and
covers the target rule and an anchor outside the editor.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Description
The editor's link click handler took
event.targetas the link. When the click landed on an element inside the anchor, it fell back to the rawhreffrom editor state, checked it with a pattern that does not normalise the value the way the browser's URL parser does, and passed it towindow.openwith a storedtargetand nonoopener.closest("a")(inside the editor root) and opens only that anchor's browser-resolvedhref; the editor-state fallback is gone.isDangerousHref, now exported) is applied at click time;file:andabout:stay blocked.noopener,noreferrer. Only_selfis honoured as a target; anything else opens a new tab.Behavior change: a link whose stored
targetis a named window now opens in a new tab.Notes for review:
clickHandler.tsnow importsisDangerousHreffrom../extension, which importsclickHandler. Both are used only at call time and the build, type check and tests pass; happy to move the function intohelpers/instead.optionsparameter is unused now and kept to avoid colliding with fix(editor): left-click on a link in read-only content opens two tabs #10179.Type of Change
Screenshots and Media (if applicable)
Test Scenarios
packages/editor/src/extensions/__tests__/custom-link.test.ts: a click on an element inside a link opens the anchor's own URL withnoopener,noreferrer, andisDangerousHrefrejects whitespace- and control-character-prefixed schemes. Editor suite: 16 passed; the click test fails without the fix.Not run in a browser. Please check manually: clicking plain and bold links in editable and read-only editors opens a new tab (not a popup window).
References
Created with Claude Code