feat(url): percent-encode filename path segments in copied URLs#3
Open
erbanku wants to merge 2 commits into
Open
feat(url): percent-encode filename path segments in copied URLs#3erbanku wants to merge 2 commits into
erbanku wants to merge 2 commits into
Conversation
Spaces and special characters in filenames were copied as-is into the clipboard URL instead of being percent-encoded, causing links to fail in some clients. - Add `percent_encode_segment` and `percent_encode_r2_key` helpers in the Rust engine and apply them in `build_public_url`, fixing the root source that writes to history DB and powers notification actions - Encode each r2Key path segment in `QueueViewModel.copyURL` and `HistoryViewModel.resolveURL` using `urlPathAllowed`, preserving `/` separators between segments - Re-encode legacy unencoded stored URLs in the history fallback path via `URLComponents` for backward compatibility - Add four new Rust unit tests covering spaces, parens, multi-segment paths, and unreserved character pass-through - Fix pre-existing compile error in config.rs test (missing `allow_anonymous_telemetry` field) Closes superhumancorp#2
There was a problem hiding this comment.
Pull request overview
This PR fixes URL generation/copying so filenames containing spaces and other characters are percent-encoded per-path-segment (without encoding / separators), improving link reliability across clients while keeping legacy history entries working.
Changes:
- Add RFC 3986 segment percent-encoding in the Rust engine’s
build_public_urland expand unit test coverage. - Encode
r2Keypath segments when copying URLs from Queue and resolving URLs from History, including a legacy-history fallback re-encode. - Fix a Rust config test compile failure by adding the missing
allow_anonymous_telemetryfield.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| app/R2Drop/App/Queue/QueueViewModel.swift | Percent-encodes each r2Key path segment when copying public URLs. |
| app/R2Drop/App/History/HistoryViewModel.swift | Encodes r2Key segments for custom domains and re-encodes stored legacy URLs for backward compatibility. |
| app/engine/r2-core/src/runner.rs | Adds strict per-segment percent-encoding in build_public_url and new unit tests. |
| app/engine/r2-core/src/config.rs | Fixes test setup by including allow_anonymous_telemetry and minor formatting changes. |
Comments suppressed due to low confidence (1)
app/R2Drop/App/Queue/QueueViewModel.swift:345
base.hasPrefix("http")treats any custom domain starting with "http" (e.g.httpfiles.example.com) as already including a scheme, producing a schemeless URL. Check forhttp://orhttps://explicitly before omitting the default scheme.
if let domain = account.customDomain, !domain.isEmpty {
let base = domain.hasSuffix("/") ? String(domain.dropLast()) : domain
let scheme = base.hasPrefix("http") ? "" : "https://"
url = "\(scheme)\(base)/\(r2Key)"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Build URL from custom domain + r2Key. | ||
| // Percent-encode each segment without encoding '/' separators. | ||
| let base = domain.hasSuffix("/") ? String(domain.dropLast()) : domain | ||
| let scheme = base.hasPrefix("http") ? "" : "https://" |
Comment on lines
+93
to
+97
| if let components = URLComponents(string: entry.url), | ||
| let host = components.host | ||
| { | ||
| let scheme = components.scheme ?? "https" | ||
| let encodedPath = components.path |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spaces and special characters in filenames were copied as-is into the clipboard URL instead of being percent-encoded, causing links to fail in some clients.
percent_encode_segmentandpercent_encode_r2_keyhelpers in the Rust engine and apply them inbuild_public_url, fixing the root source that writes to history DB and powers notification actionsQueueViewModel.copyURLandHistoryViewModel.resolveURLusingurlPathAllowed, preserving/separators between segmentsURLComponentsfor backward compatibilityallow_anonymous_telemetryfield)Closes #2