qBitControl
qBitControl copied to clipboard
[Fix] sanitize the server url for trailing slashes while adding a server
Summary
Normalize user-entered server URLs by removing any trailing slash characters before saving or testing the connection. This ensures consistent URL formatting across the app and avoids duplicate entries or subtle connection issues caused by extra slashes.
What changed
- Added
sanitizeInputs()toServerAddViewModelthat strips trailing slashes using a regex:url = url.replacingOccurrences(of: "/+$", with: "", options: .regularExpression)
- Invoked
sanitizeInputs()at the start ofaddServer(dismiss:), after input validation and before:- building the
Servermodel - attempting a connection check
- persisting the server
- building the
Why this is needed
- Users may paste URLs ending with
/or multiple///. - Trailing slashes can lead to:
- Mismatched URLs when comparing or deduplicating servers
- Inconsistent request paths when constructing endpoints
- Confusing UI where the same server appears as different entries
Normalizing the URL at the point of creation/editing prevents these issues and keeps storage/logic consistent.
How it works
- The regex
"/+$"matches one or more slashes at the end of the string and removes them. - Examples:
https://example.com/→https://example.comhttp://example.com///→http://example.com
- Note: This field represents the base server URL; normalizing to the host/root avoids accidental path suffixes.
Risk assessment
- Low risk. Only trailing slashes are removed; scheme, host, ports, and credentials remain unchanged.
- No behavioral change when the URL is already normalized.
Testing
- Manually verified adding servers with:
https://example.com/→ saved ashttps://example.comhttp://example.com///→ saved ashttp://example.com
- Confirmed connectivity check runs against the sanitized URL.
- Edited an existing server with trailing slashes and confirmed it is normalized upon save.
Hi, thanks for the PR. I'll check it out and merge when I can.