Skip to content

Match path configuration rules against the normalized url - #223

Merged
mbarta merged 3 commits into
mainfrom
path-config-url-parsing
Nov 5, 2026
Merged

mbarta merged 3 commits into
mainfrom
path-config-url-parsing

Conversation

@mbarta

@mbarta mbarta commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Path configuration rules now match an http(s) url in the same form the WebView loads it. Before, PathConfigurationData read the path with java.net.URL, which keeps a url exactly as written, so a url that isn't in canonical form could get different properties than the page it loads.

  • Tabs and newlines are removed from the whole url first, like the WebView does.
  • http(s) urls then go through OkHttp's HttpUrl, which Hotwire already uses for origins. It reads backslashes as slashes and resolves dot segments. An http(s) url it can't parse matches no rules.
  • A url without a path keeps its empty path, so ^/$ rules don't start matching a bare host.
  • Other schemes, like mailto:, still go through java.net.URL.
  • Paths and queries are matched in their percent-encoded form. A rule with a literal non-ASCII character, like ^/café$, needs its encoded form, ^/caf%C3%A9$, which is also how the WebView requests it. OkHttp encodes | and ^ in paths too, which the WebView keeps, so a rule that matches those literally needs %7C and %5E.
  • A form feed is percent-encoded before parsing, like the WebView does, instead of dropped.

I checked every url literal in 3 apps' code and tests against the old and new parsing. Only urls with a trailing backslash differ, and those now match the way the WebView loads them.

🤖 Generated with Claude Code

Milan Barta and others added 3 commits November 5, 2026 15:39
PathConfigurationData parsed the location with java.net.URL, which keeps a url
exactly as written. The WebView and OkHttp normalize it before loading, so a url
that isn't in canonical form could match different rules than the page it loads.

http(s) locations now go through OkHttp's HttpUrl, which Hotwire already uses for
origins. A url without a path keeps its empty path, and other schemes still use
java.net.URL, so their matching doesn't change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The WebView removes tabs and newlines from the whole url, including the host,
before it parses it. OkHttp only skips them in the path, so a url with one in
its host fell back to java.net.URL. Now path() removes them first, and an
http(s) url that still doesn't parse matches no rules.

Whether a url has a path now comes from the text after its host, so
"https://example.com\" matches the root path like the WebView loads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OkHttp drops a form feed from the path, while the WebView percent-encodes it,
so "/files/\f../other" matched as "/other" but loaded as "/files/%0C../other".
path() now encodes form feeds before OkHttp parses the url.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mbarta
mbarta marked this pull request as ready for review November 5, 2026 15:52
@mbarta
mbarta merged commit eae7f05 into main Nov 5, 2026
1 check passed
@mbarta
mbarta deleted the path-config-url-parsing branch November 5, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant