Skip to content

Internet values

Code that takes an email, a URL or an IP address checks it, stores it and sends it on, and each step has its own idea of what’s valid. strings().matching(…) can draw one, but writing the regex is the hard part, and a value that passes it is only as valid as the regex. The internet module draws each by construction in a profile it names, so every value it draws, and every value a failure shrinks to, is in that profile.

The words are in a jar of their own, on Maven Central, which needs only the library:

build.gradle.kts
dependencies {
testImplementation("io.proptastic:proptastic-internet:1.0.0")
}

They’re static methods of io.proptastic.internet.Internet.

Word Draws Shrinks toward
ipAddresses() an InetAddress, version 4 first, then version 6, each part a number 0.0.0.0
domains() an RFC 1123 host name: one to three labels, then com, org, net, io, dev or the reserved example a.com
domains(topLevel) as domains(), under the top-level domains topLevel draws a. and the first
emails() an address RFC 5322’s dot-atom and HTML both accept, at a host as domains() draws it [email protected]
emails(hosts) as emails(), at the hosts hosts draws a@ and the first
urls() an absolute https or http URL a WHATWG parser leaves as it is https://a.com/
urls(hosts) as urls(), at the hosts hosts draws https://, the first, /

About one try in 8, each draws an edge:

  • IP addresses: 0.0.0.0, loopback, broadcast, the private ranges, link-local, shared address space and multicast, then version 6’s ::, ::1, fe80::1, the documentation range’s 2001:db8::1, ff02::1 and the IPv4-mapped ::ffff:127.0.0.1, which stays version 6.
  • Host names: a label of digits only, a hyphen inside a label, an internationalized name’s xn-- form, a label of 63 characters.
  • Emails: a + tag, a dot in the local part, and every symbol a local part may have.
  • Host names are lower-case letters, digits and hyphens, each label 1 to 63 characters with no hyphen at either end, at most 253 in all. .arpa is never drawn: validators refuse it. No drawn label starts xn-- but the edge’s, a real internationalized name, as a parser checks one. With a long top-level domain of your own, leading labels are dropped to stay within 253.
  • Emails have a local part of up to three atoms of a-z, 0-9 and !#$%&'*+/=?^_`{|}~- between dots, at most 254 characters in all. No quoted local part, comment or address literal: RFC 5322 allows them, and many validators don’t. To test those, draw them yourself.
  • URLs have a port only when it isn’t the scheme’s own, a path of up to three segments that are never . or .., a query without ', and an optional fragment, so a WHATWG parser, a browser’s, gives back the same text. No user name, password or percent-encoding yet.

domains() is named for host names, as other libraries name it, though a domain in proptastic is a source of values. Being provisional, the name can still change.

Vocabulary has every word, in every edition.

Privacy