fix: strip URI scheme prefixes from hostname input#533
fix: strip URI scheme prefixes from hostname input#533torlando-tech merged 1 commit intorelease/v0.8.xfrom
Conversation
Users pasting URLs like "http://rns.soon.it" instead of bare hostnames caused a fatal IllegalStateException when editing the interface config. validateHostname() now strips http:// and https:// prefixes, and callers use the cleaned value instead of the raw input. Fixes COLUMBA-43 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR fixes a crash (
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["User enters hostname\n(e.g., http://rns.soon.it)"] --> B["InputValidator.validateHostname()"]
B --> C["Strip scheme prefix\n(http:// / https://)"]
C --> D["Strip trailing slash\nand path components"]
D --> E{"Validate cleaned\nhostname"}
E -->|Valid| F["ValidationResult.Success\n(cleaned value)"]
E -->|Invalid| G["ValidationResult.Error"]
F --> H["ViewModel:\nWrite back to _configState\n(targetHost / listenIp)"]
F --> I["Repository:\nentityToConfig uses\ncleaned value"]
H --> J["User sees sanitized\nhostname in UI"]
I --> K["InterfaceConfig created\nwith clean hostname"]
G --> L["Error shown to user"]
style C fill:#d4edda,stroke:#28a745
style D fill:#d4edda,stroke:#28a745
style H fill:#d4edda,stroke:#28a745
style I fill:#fff3cd,stroke:#ffc107
Last reviewed commit: 7e2138f |
| val cleaned = | ||
| host | ||
| .trim() | ||
| .removePrefix("http://") | ||
| .removePrefix("https://") | ||
| .removeSuffix("/") | ||
| .split("/") | ||
| .first() // Strip any path component after the hostname |
There was a problem hiding this comment.
URLs with port numbers produce confusing errors
If a user pastes http://example.com:8080, this logic produces example.com:8080 after stripping the scheme. The :8080 portion is not a valid hostname character, so validation fails with "Invalid hostname or IP address" — which is technically correct but may confuse users.
Consider also stripping a trailing :port component (e.g., via split(":").first()), or at minimum providing a more specific error message when a colon is detected in the cleaned value (e.g., "Remove the port number — enter hostname and port separately").
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/src/main/java/com/lxmf/messenger/util/validation/InputValidator.kt
Line: 286-293
Comment:
**URLs with port numbers produce confusing errors**
If a user pastes `http://example.com:8080`, this logic produces `example.com:8080` after stripping the scheme. The `:8080` portion is not a valid hostname character, so validation fails with "Invalid hostname or IP address" — which is technically correct but may confuse users.
Consider also stripping a trailing `:port` component (e.g., via `split(":").first()`), or at minimum providing a more specific error message when a colon is detected in the cleaned value (e.g., "Remove the port number — enter hostname and port separately").
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
The Similarly, the Consider applying the same Prompt To Fix With AIThis is a comment left during a code review.
Path: app/src/main/java/com/lxmf/messenger/repository/InterfaceRepository.kt
Line: 274-280
Comment:
**RNode TCP host not sanitized on read**
The `TCPClient` and `TCPServer` branches were updated to use `hostResult.value` (the cleaned hostname), but the `RNode` TCP-mode branch at line 274–280 still uses the old `else -> {}` pattern and passes the raw `tcpHost` to `InterfaceConfig.RNode` at line 308. If a user stores `http://somehost` as an RNode TCP host, it will not be sanitized on read — the same class of bug this PR fixes for `TCPClient`/`TCPServer`.
Similarly, the `UDP` interface branch (lines 332–346) uses the same old pattern for `listenIp` and `forwardIp`, discarding the cleaned value.
Consider applying the same `val cleanedHost = when (...) { Success -> result.value }` pattern here for consistency.
How can I resolve this? If you propose a fix, please make it concise. |
…vel stripping Address Greptile review feedback on #533: - Strip trailing :port from hostnames (e.g. "example.com:8080" → "example.com") - Use cleaned values from validateHostname() in RNode TCP and UDP entityToConfig branches - Strip http:// and https:// in UI text field onValueChange handlers for immediate feedback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…vel stripping Address Greptile review feedback on #533: - Strip trailing :port from hostnames (e.g. "example.com:8080" → "example.com") - Use cleaned values from validateHostname() in RNode TCP and UDP entityToConfig branches - Strip http:// and https:// in UI text field onValueChange handlers for immediate feedback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
validateHostname()now stripshttp://andhttps://prefixes (and any path component) before validation, so users who paste a full URL get the hostname extracted automaticallyentityToConfig()uses the cleaned value from validation, fixing existing poison data in the database on readvalidateConfigState()writes the cleaned hostname back to UI state so subsequent saves persist the sanitized valueContext
Fixes COLUMBA-43 — users entering
http://rns.soon.itas a TCP host caused a fatalIllegalStateExceptionwhen editing the interface config. 5 occurrences across 2 users on v0.8.12-beta.Test plan
InputValidatorTest,InterfaceRepositoryTest, andInterfaceManagementViewModelTestpasshttp://rns.soon.itas TCP host, verify it saves asrns.soon.it🤖 Generated with Claude Code