Skip to content

shell: validate default TextView link URLs - #3048

Open
lurenjia534 wants to merge 1 commit into
longbridge:mainfrom
lurenjia534:fix/textview-link-url-validation
Open

shell: validate default TextView link URLs#3048
lurenjia534 wants to merge 1 commit into
longbridge:mainfrom
lurenjia534:fix/textview-link-url-validation

Conversation

@lurenjia534

Copy link
Copy Markdown
Contributor

Description

When no script on_link_click callback is provided, Shell inherits gpui-base::TextView's default link handling. HTML and Markdown links can therefore reach App::open_url without the URL validation already enforced by Link.href and the script-facing cx.open_url.

Install a Shell-owned default handler that applies the same validation: a parsed HTTP(S) URL with a host. Preserve the existing activation conditions and leave explicit script callbacks unchanged.

This PR only changes default link activation in Shell and adds focused regression tests. Base APIs, image loading, and network capability handling are unchanged.

How to Test

cargo test --locked -p gpui-shell --lib text_view_default_links_follow_shell_url_rules -- --nocapture
cargo test --locked -p gpui-shell --lib text_view_link_callback_still_replaces_default_opening -- --nocapture
cargo fmt --all -- --check

Verified the behavior before and after the fix:

  • Non-HTTP(S), relative, and invalid targets are no longer forwarded to App::open_url. Valid HTTP(S) links still open on left/middle click.
  • Right-click still does not trigger default opening.
  • Explicit on_link_click callbacks still receive the original URL without triggering default opening.

Both regression tests passed: 36 default-link combinations and 12 callback combinations, covering HTML and Markdown with left, middle, and right mouse buttons. Formatting checks also passed.

Link opening is checked through GPUI's test context; these tests do not launch actual OS URL handlers.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific). N/A: no platform-specific implementation changes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant