Skip to content

Commit

Permalink
Allow underscores in host (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostverdoorn authored and sindresorhus committed Apr 21, 2019
1 parent 6422d95 commit 7313fb0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = options => {
const protocol = `(?:(?:[a-z]+:)?//)${options.strict ? '' : '?'}`;
const auth = '(?:\\S+(?::\\S*)?@)?';
const ip = ipRegex.v4().source;
const host = '(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)';
const host = '(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)';
const domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*';
const tld = `(?:\\.${options.strict ? '(?:[a-z\\u00a1-\\uffff]{2,})' : `(?:${tlds.sort((a, b) => b.length - a.length).join('|')})`})\\.?`;
const port = '(?::\\d{2,5})?';
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test('match exact URLs', t => {
'http://www.example.com/wpstyle/?p=364',
'https://www.example.com/foo/?bar=baz&inga=42&quux',
'http://a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.com',
'http://a_b.z.com',
'http://mw1.google.com/mw-earth-vectordb/kml-samples/gp/seattle/gigapxl/$[level]/r$[y]_c$[x].jpg',
'http://user:[email protected]:123/one/two.three?q1=a1&q2=a2#body',
'http://www.microsoft.xn--comindex-g03d.html.irongeek.com',
Expand Down Expand Up @@ -118,6 +119,8 @@ test('do not match URLs', t => {
'http://.www.foo.bar./',
'http://go/ogle.com',
'http://foo.bar/ /',
'http://a.b_z.com',
'http://ab_.z.com',
'http://google\\.com',
'http://www(google.com',
'http://www.example.xn--overly-long-punycode-test-string-test-tests-123-test-test123/',
Expand Down

0 comments on commit 7313fb0

Please sign in to comment.