Skip to content

fix(webview): resolve relative urls against the article link - #1350

Open
TommyBacco wants to merge 2 commits into
ReadYouApp:mainfrom
TommyBacco:fix/webview-base-url
Open

TommyBacco wants to merge 2 commits into
ReadYouApp:mainfrom
TommyBacco:fix/webview-base-url

Conversation

@TommyBacco

Copy link
Copy Markdown

Problem

The WebView renderer composes the article HTML with a <base href="%s"> slot, but fills it with WebView.getUrl() — which is null before the first load and about:blank afterwards. Consequently every relative or protocol-relative URL in the article content resolves against an invalid base, producing broken images and dead links (and, for embeds, null/... style URLs that the WebView cannot load).

Changes

  • RYWebView gains a baseUrl parameter. Content passes the article link.
  • WebViewHtml.resolveBaseUrl() normalizes the link (protocol-relative //host/... and scheme-less inputs get https://, reusing the existing formatUrl()), validates it through java.net.URI and only accepts http(s)/file origins, otherwise returning an empty base.
  • The base is also HTML-escaped (WebViewHtml.escapeAttribute()) before being injected into <base href="...">, so links containing quotes or & cannot break out of the attribute.

Notes

  • The empty/invalid base falls back to exactly the previous behaviour (loadDataWithBaseURL(null, …)), so no regression for feeds without usable article links.

Tests

  • WebViewHtmlTest.testResolveBaseUrl — null/blank, absolute, protocol-relative, scheme-less, invalid-URI (space in path) and hostile-scheme (javascript:) inputs.
  • WebViewHtmlTest.testEscapeAttribute — &, ", <, > escaping.
  • Full suite: ./gradlew testGithubReleaseUnitTest

Stack

This is the first PR of a stack; the follow-ups are opened as drafts against the fork branches and will be retargeted here as this merges:

Feed-controlled article links must not set a file: base, since
allowFileAccess is enabled for external reading fonts and a file base
would let article content resolve relative references to local files.
@TommyBacco
TommyBacco marked this pull request as ready for review November 2, 2026 08:24
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