Skip to content

Commit

Permalink
Fixed a bug preventing hostnames from being validated w/o periods
Browse files Browse the repository at this point in the history
Fixed for URLs like:
- http://instance-data/latest/dynamic/instance-identity/document
  • Loading branch information
danielbankhead committed Mar 4, 2017
1 parent 6696ff5 commit da33790
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Empty file modified index.js
100644 → 100755
Empty file.
Empty file modified lib/progress-logger.js
100644 → 100755
Empty file.
Empty file modified lib/request.js
100644 → 100755
Empty file.
2 changes: 0 additions & 2 deletions lib/url-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ function parseURL (candidate, options) {
if (results.options.localhostAllowed === false) {
return results
}
} else if (results.parsedURL.hostname.includes('.') === false) {
return results
} else if (/(^[.-])|([.-]$)/.test(results.parsedURL.hostname)) {
// hostname should not start with -. nor end with it
return results
Expand Down
21 changes: 12 additions & 9 deletions tests/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ if (platform === 'win32') {
socket = `/${testIdentifier}.sock`
}

} else if (results.parsedURL.hostname.includes('.') === false) {
return results


// url
// https://mathiasbynens.be/demo/url-regex
// List extracted from: https://mathiasbynens.be/demo/url-regex
const valid = [
'http://foo.com/blah_blah',
'http://foo.com/blah_blah/',
Expand Down Expand Up @@ -64,7 +66,8 @@ const valid = [
'http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com',
'http://1337.net',
'http://a.b-c.de',
'http://223.255.255.254'
'http://223.255.255.254',
'http://instance-data/latest/dynamic/instance-identity/document'
]

const invalid = [
Expand Down Expand Up @@ -109,15 +112,15 @@ const invalid = [
'http://10.1.1.254'
]

valid.forEach(item => {if(up(item).isValid === false) {console.log(item)} })
valid.forEach(item => {
if (jetta.urlParser(item).isValid === false) {
console.log(item)
}
})

invalid.forEach(item => {
const r = up(item, {addMissingProtocol: true})
if (r.isValid === true) {
console.log(`\`${item}\` hostname: \`${r.parsedURL.hostname}\``)
if (jetta.urlParser(item, {addMissingProtocol: true}).isValid === true) {
console.log(item)
}
})



```

0 comments on commit da33790

Please sign in to comment.