Require the IPv6: tag for bracketed IPv6 email literals#428
Conversation
garydgregory
left a comment
There was a problem hiding this comment.
This is now a mix of RegEx and string matching. Shouldn't it be possible to update the regex and keep it at that?
|
Fair point, the regionMatches/substring pair was doing work the pattern could do itself. I've moved the tag into IP_DOMAIN_REGEX as an optional capture group, Behaviour is unchanged from the previous revision: tagged literals validate as IPv6 in any case, untagged ones as IPv4 only. The new test still passes and the full default mvn goal (rat, japicmp, checkstyle, spotbugs, pmd, javadoc) is BUILD SUCCESS. |
Added Javadoc comment for IP_DOMAIN_REGEX to clarify its purpose.
mvn; that'smvnon the command line by itself.EmailValidator.isValidDomainhands the contents of a bracketed host toInetAddressValidator.isValid, which accepts an IPv4 or an IPv6 address without distinguishing them. RFC 5321 section 4.1.3 tags an IPv6 address literal withIPv6:and leaves an IPv4 literal untagged, so the current code is wrong at both ends: it accepts a bareuser@[::1], which no conformant parser should, and rejects the correctly taggeduser@[IPv6:::1]because theIPv6:prefix reachesInetAddressValidatoras part of the address and the parse fails. I came across it while checking why a valid IPv6 literal was being turned away when the malformed bare form validated.The fix matches the
IPv6:tag on the bracket contents, case insensitively since it is ABNF-literal text, and validates the remainder as IPv6; an untagged literal is validated as IPv4 only. Keeping the split inisValidDomainleaves the IPv4-versus-IPv6 rule in the one place that parses the bracketed host, and the deprecatedvalidator.EmailValidatorinherits it because itsisValiddelegates here. Left unfixed, an allow-list built on this treats a bare loopback or link-local literal that no conformant MTA routes as valid while refusing the RFC form.