Skip to content

fix: strip port from pasted URLs, sanitize RNode/UDP hosts#538

Merged
torlando-tech merged 3 commits intorelease/v0.8.xfrom
fix/hostname-port-strip-v0.8.x
Feb 24, 2026
Merged

fix: strip port from pasted URLs, sanitize RNode/UDP hosts#538
torlando-tech merged 3 commits intorelease/v0.8.xfrom
fix/hostname-port-strip-v0.8.x

Conversation

@torlando-tech
Copy link
Copy Markdown
Owner

Summary

Follow-up to #533, addressing Greptile review feedback:

  • Strip trailing :port from hostnames (e.g. http://example.com:8080example.com)
  • Use cleaned values from validateHostname() in RNode TCP and UDP entityToConfig() branches (previously discarded)
  • Strip http:// and https:// in UI text field onValueChange handlers for immediate visual feedback

Test plan

  • 2 new unit tests for port stripping (URL with port, bare hostname with port)
  • All existing InputValidator, InterfaceRepository, and InterfaceManagementViewModel tests pass
  • Manual: paste http://example.com:8080 in TCP host field, verify it becomes example.com

🤖 Generated with Claude Code

…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>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 23, 2026

Greptile Summary

Addresses Greptile review feedback from #533 by implementing a safer port-stripping strategy using colon count rather than regex matching. The PR correctly fixes the previously identified IPv6 corruption issue by checking if a string has exactly one colon before applying port stripping logic.

Key improvements:

  • Port stripping now uses colon count (== 1) to distinguish hostname:port from IPv6 addresses (multiple colons)
  • Cleaned hostname values from validateHostname() are now properly used in InterfaceRepository instead of being discarded
  • UI text fields strip http:// and https:// prefixes immediately for better user feedback
  • Comprehensive test coverage added for port stripping and IPv6 protection

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation correctly addresses the previous review feedback with a sound algorithmic approach (colon counting), includes comprehensive test coverage for edge cases, and properly integrates the cleaned values throughout the codebase. The logic is defensive and well-documented.
  • No files require special attention

Important Files Changed

Filename Overview
app/src/main/java/com/lxmf/messenger/util/validation/InputValidator.kt Improved port stripping logic using colon count instead of regex to safely handle IPv6 addresses
app/src/main/java/com/lxmf/messenger/repository/InterfaceRepository.kt Now uses cleaned values from validateHostname() for RNode TCP and UDP hosts instead of discarding them
app/src/main/java/com/lxmf/messenger/ui/components/InterfaceConfigDialog.kt Added UI-level URL scheme stripping for immediate visual feedback when users paste URLs
app/src/test/java/com/lxmf/messenger/util/validation/InputValidatorTest.kt Added comprehensive tests for port stripping and IPv6 address protection

Last reviewed commit: 0db9d43

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Add IPV6_REGEX check before port-stripping to prevent corrupting
IPv6 addresses like "2001:db8::1" where the trailing ":1" looks
like a port number.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@torlando-tech
Copy link
Copy Markdown
Owner Author

@greptileai

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +289 to +297
fun `validateHostname - does not strip segments from IPv6 address`() {
// IPv6 like "2001:db8::1" ends with ":1" which could look like a port
val validIPv6 = listOf("2001:db8:85a3:0:0:8a2e:370:7334", "fe80:0:0:0:0:0:0:1")
validIPv6.forEach { ipv6 ->
val result = InputValidator.validateHostname(ipv6)
assertTrue("$ipv6 should be valid", result is ValidationResult.Success)
assertEquals(ipv6, result.getOrNull())
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test for ::1 and other compressed IPv6 forms

Test only covers full/uncompressed IPv6. Missing critical cases:

  • ::1 (loopback)
  • fe80::1 (link-local)
  • ::ffff:192.0.2.1 (IPv4-mapped)

These would fail with current implementation due to incomplete IPV6_REGEX.

Prompt To Fix With AI
This is a comment left during a code review.
Path: app/src/test/java/com/lxmf/messenger/util/validation/InputValidatorTest.kt
Line: 289-297

Comment:
Missing test for `::1` and other compressed IPv6 forms

Test only covers full/uncompressed IPv6. Missing critical cases:
- `::1` (loopback)
- `fe80::1` (link-local)
- `::ffff:192.0.2.1` (IPv4-mapped)

These would fail with current implementation due to incomplete `IPV6_REGEX`.

How can I resolve this? If you propose a fix, please make it concise.

@torlando-tech
Copy link
Copy Markdown
Owner Author

@greptileai

Compressed IPv6 like "::1" or "fe80::1" aren't matched by IPV6_REGEX
and would be corrupted by port stripping. Instead of fixing the regex,
use a simpler invariant: IPv6 always has multiple colons, hostname:port
has exactly one.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@torlando-tech
Copy link
Copy Markdown
Owner Author

@greptileai

@torlando-tech torlando-tech merged commit f19ff63 into release/v0.8.x Feb 24, 2026
2 checks passed
@torlando-tech torlando-tech deleted the fix/hostname-port-strip-v0.8.x branch February 24, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant