Add hostname matching to Joi.String#210
Add hostname matching to Joi.String#210osslate wants to merge 10 commits intohapijs:masterfrom osslate:master
Conversation
|
Why not enforce length if it is part of the spec? Also, need more test cases like numbers. |
|
Will add a check for the length and add some tests. |
|
Note that this does not include IPv6 hostname support. |
|
It's not designed to match IP addresses in particular, it's designed to match hostnames (which does include any IPv4 address as they're technically valid hostnames). |
|
Yup, but IPv6 addresses are also technically valid hostnames. |
|
Do you know of any regular expressions that can match hostnames (including IPv4 and IPv6)? I looked specifically through the RFCs for a reference when I implemented this, can't find much on IPv6 hostnames. |
|
Am I correct in assuming that joi is Node-only? If so, I'd recommend using the In a URL/URI, IPv6 hostnames are special, and must be wrapped with square brackets, but they stand alone as just a hostname (so you should just be able to pass the provided hostname straight to the isIP function, and if it fails pass it to a regex > url.parse('https://[fe80::d63d:7eff:feda:d3a7]:3000/resource')
{ protocol: 'https:',
slashes: true,
auth: null,
host: '[fe80::d63d:7eff:feda:d3a7]:3000',
port: '3000',
hostname: 'fe80::d63d:7eff:feda:d3a7',
hash: null,
search: null,
query: null,
pathname: '/resource',
path: '/resource',
href: 'https://[fe80::d63d:7eff:feda:d3a7]:3000/resource' }
> net.isIP('fe80::d63d:7eff:feda:d3a7')
6 |
|
Completely forgot about the url/net module. Will push a fix later on. |
|
I used regex.match() due to it being used everywhere else throughout Joi rather than .test(). |
|
Ah, fair enough. Consistency over correctness. |
|
We just got joi compatible with browserify. Will this break it? |
|
Yep. Darn, that would've been nice. Edit: Actually, I'm not sure. Does browserify's |
|
Apparently it doesn't provide anything: https://github.com/substack/node-browserify/blob/master/lib/builtins.js#L16 It'd be easy to whip out the isIPv6 function from Node, but I'm not sure if it's worthwhile. |
|
Can you update this to the master branch? |
|
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Match hostnames as defined in RFC1123 - note that this doesn't validate the length, which can be a maximum of 255 characters.