Skip to content

Validate IP-like hosts in UriAttribute and extend test coverage#359

Merged
davidkallesen merged 1 commit into
mainfrom
feature/improve-UriAttribute-validation
Apr 10, 2026
Merged

Validate IP-like hosts in UriAttribute and extend test coverage#359
davidkallesen merged 1 commit into
mainfrom
feature/improve-UriAttribute-validation

Conversation

@davidkallesen

Copy link
Copy Markdown
Collaborator

Summary

Uri.TryCreate accepts malformed IP addresses like 1231.0.0.1 by misclassifying them as DNS hostnames. This PR adds host validation to UriAttribute.IsValid that detects hosts consisting solely of digits and dots (IP-like) but not recognized as valid IPv4, and rejects them. It also significantly extends test coverage for IPAddressAttribute, UriAttribute, and the URI string extension methods.

Changes

🐛 Fixes

  • Reject URIs with malformed IP-like hosts (e.g. opc.tcp://1231.0.0.1:4840, http://999.999.999.999:8080) that Uri.TryCreate
    incorrectly accepts as DNS names

✅ Tests

  • Extend IPAddressAttributeTests with comprehensive IPv4/IPv6 coverage, edge cases, required/optional, and TryIsValid with
    attribute overload
  • Add invalid IP host and valid IP host test cases across UriAttributeTests for IsValid, TryIsValid, IsValidHttpOrHttps,
    TryIsValidHttpOrHttps, IsValidOpcTcp, and TryIsValidOpcTcp
  • Add port boundary test cases (0, 65535, 65536) documenting that out-of-range ports are correctly rejected
  • Add IP and port test cases to StringHasIsExtensionsTests for IsUri, IsUriHttpOrHttps, and IsUriOpcTcp

📝 Documentation

  • Add XML documentation to the private IsHostValid helper explaining the detection strategy

perkops
perkops previously approved these changes Apr 10, 2026
@davidkallesen davidkallesen force-pushed the feature/improve-UriAttribute-validation branch from 0101ae7 to ea259d3 Compare April 10, 2026 13:46
@davidkallesen davidkallesen merged commit 11c487f into main Apr 10, 2026
4 checks passed
@davidkallesen davidkallesen deleted the feature/improve-UriAttribute-validation branch April 10, 2026 13:52
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.

2 participants