Skip to content

Replace hand-rolled file-URL encoder with url::Url::from_file_path#44

Closed
kasnder wants to merge 2 commits into
mainfrom
fix/file-url-test
Closed

Replace hand-rolled file-URL encoder with url::Url::from_file_path#44
kasnder wants to merge 2 commits into
mainfrom
fix/file-url-test

Conversation

@kasnder

@kasnder kasnder commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Problem

web_automation::tests::file_url_encodes_spaces has been failing since the product rename: it fed path_to_file_url a "ReDD Blocker.app" path but asserted the pre-rename ReDD%20Block.app URL.

The deeper issue wasn't the stale string — it's that path_to_file_url + pct_encode_path_segment hand-rolled file-URL percent-encoding, guarded by a single test that itself hardcoded the product name.

Fix

  • Delete the hand-rolled encoder and delegate to url::Url::from_file_path — the url crate is already in the dependency tree via Tauri (2.5.8 in the lockfile), so declaring it as a direct dependency adds no new compiled code.
  • path_to_file_url now returns Option<String> (the crate rejects relative paths); resolve_block_page_url logs and declines to start the watcher in that case, same as the existing missing-resource-dir path.
  • Tests cover spaces, non-ASCII, and relative-path rejection using product-agnostic fixture paths, so a future rename can't break them.

Block-page detection is unaffected: is_block_page_url keeps its normalization-tolerant fallback (contains("blocked/blocked.html")), and the base URL is generated once and used for both the AppleScript set URL and the comparison, so both sides stay consistent. The query-string pct_encode/pct_decode helpers are untouched — they intentionally mirror the extension's background.js.

cargo test --lib: 30 passed, 0 failed.

🤖 Generated with Claude Code

kasnder and others added 2 commits July 7, 2026 23:12
The test fed path_to_file_url a "ReDD Blocker.app" path but asserted
the pre-rename "ReDD%20Block.app" URL, so it has failed since the
product rename. Use a product-agnostic fixture path instead — the test
is about percent-encoding, not the bundle name, so a future rename
can't break it again.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
path_to_file_url + pct_encode_path_segment reimplemented file-URL
percent-encoding by hand, guarded by a single test that itself proved
brittle (it hardcoded the pre-rename bundle name). Delegate to the url
crate instead — already in the dependency tree via Tauri, so this adds
no new compiled code — and surface its relative-path rejection as an
Option handled at the resolve_block_page_url call site.

Tests now cover spaces, non-ASCII, and relative-path rejection with a
product-agnostic fixture, so a future app rename can't break them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kasnder kasnder changed the title Fix file_url_encodes_spaces test and decouple it from the product name Replace hand-rolled file-URL encoder with url::Url::from_file_path Jul 7, 2026
@kasnder

kasnder commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Closing — folding the one-line test fix into #43 instead, which is where the failing test shows up.

@kasnder kasnder closed this Jul 7, 2026
@kasnder kasnder deleted the fix/file-url-test branch July 7, 2026 21:23
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