Skip to content

Commit 7313fb0

Browse files
joostverdoornsindresorhus
authored andcommitted
Allow underscores in host (#56)
1 parent 6422d95 commit 7313fb0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = options => {
1111
const protocol = `(?:(?:[a-z]+:)?//)${options.strict ? '' : '?'}`;
1212
const auth = '(?:\\S+(?::\\S*)?@)?';
1313
const ip = ipRegex.v4().source;
14-
const host = '(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)';
14+
const host = '(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)';
1515
const domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*';
1616
const tld = `(?:\\.${options.strict ? '(?:[a-z\\u00a1-\\uffff]{2,})' : `(?:${tlds.sort((a, b) => b.length - a.length).join('|')})`})\\.?`;
1717
const port = '(?::\\d{2,5})?';

test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test('match exact URLs', t => {
1010
'http://www.example.com/wpstyle/?p=364',
1111
'https://www.example.com/foo/?bar=baz&inga=42&quux',
1212
'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',
13+
'http://a_b.z.com',
1314
'http://mw1.google.com/mw-earth-vectordb/kml-samples/gp/seattle/gigapxl/$[level]/r$[y]_c$[x].jpg',
1415
'http://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body',
1516
'http://www.microsoft.xn--comindex-g03d.html.irongeek.com',
@@ -118,6 +119,8 @@ test('do not match URLs', t => {
118119
'http://.www.foo.bar./',
119120
'http://go/ogle.com',
120121
'http://foo.bar/ /',
122+
'http://a.b_z.com',
123+
'http://ab_.z.com',
121124
'http://google\\.com',
122125
'http://www(google.com',
123126
'http://www.example.xn--overly-long-punycode-test-string-test-tests-123-test-test123/',

0 commit comments

Comments
 (0)