[Fix] sanitize the server url for trailing slashes while adding a server #84
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