[Fix] sanitize the server url for trailing slashes while adding a server#84
Open
danpiths wants to merge 2 commits intoMichael-128:mainfrom
Open
[Fix] sanitize the server url for trailing slashes while adding a server#84danpiths wants to merge 2 commits intoMichael-128:mainfrom
danpiths wants to merge 2 commits intoMichael-128:mainfrom
Conversation
### 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()` to `ServerAddViewModel` that strips trailing slashes using a regex: - `url = url.replacingOccurrences(of: "/+$", with: "", options: .regularExpression)` - Invoked `sanitizeInputs()` at the start of `addServer(dismiss:)`, after input validation and before: - building the `Server` model - attempting a connection check - persisting the server ### 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.com` - `http://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 as `https://example.com` - `http://example.com///` → saved as `http://example.com` - Confirmed connectivity check runs against the sanitized URL. - Edited an existing server with trailing slashes and confirmed it is normalized upon save.
Owner
|
Hi, thanks for the PR. I'll check it out and merge when I can. |
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.
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
sanitizeInputs()toServerAddViewModelthat strips trailing slashes using a regex:url = url.replacingOccurrences(of: "/+$", with: "", options: .regularExpression)sanitizeInputs()at the start ofaddServer(dismiss:), after input validation and before:ServermodelWhy this is needed
/or multiple///.Normalizing the URL at the point of creation/editing prevents these issues and keeps storage/logic consistent.
How it works
"/+$"matches one or more slashes at the end of the string and removes them.https://example.com/→https://example.comhttp://example.com///→http://example.comRisk assessment
Testing
https://example.com/→ saved ashttps://example.comhttp://example.com///→ saved ashttp://example.com