Skip to content

Commit

Permalink
fix: allow underscores in domain names
Browse files Browse the repository at this point in the history
Apparently, underscores are not allowed in hostnames,
but allowed in domain names.
  • Loading branch information
fczbkk committed Apr 28, 2018
1 parent 8a831e2 commit 94c33ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class extends UrlPart {
// escape all dots
{substring: '.', replacement: '\\.'},
// replace asterisks with pattern
{substring: '*', replacement: '[a-z0-9-.]+'}
{substring: '*', replacement: '[a-z0-9-_.]+'}
];
}

Expand Down
10 changes: 7 additions & 3 deletions test/host.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe('Host', function() {

it('should not validate characters except letters, numbers and -', function() {
expect(host.validate('aaa?bbb.ccc')).toBe(false);
expect(host.validate('aaa_bbb.ccc')).toBe(false);
expect(host.validate('aaa+bbb.ccc')).toBe(false);
});

Expand All @@ -68,15 +67,15 @@ describe('Host', function() {
describe('sanitize', function() {

it('should sanitize *', function() {
expect(host.sanitize('*')).toEqual(/^[a-z0-9-.]+$/);
expect(host.sanitize('*')).toEqual(/^[a-z0-9-_.]+$/);
});

it('should sanitize host without asterisk', function() {
expect(host.sanitize('aaa')).toEqual(/^aaa$/);
});

it('should sanitize host with asterisk', function() {
expect(host.sanitize('*.aaa')).toEqual(/^([a-z0-9-.]+\.)?aaa$/);
expect(host.sanitize('*.aaa')).toEqual(/^([a-z0-9-_.]+\.)?aaa$/);
});

});
Expand Down Expand Up @@ -117,6 +116,11 @@ describe('Host', function() {
expect(host.test('aaa.bbb.ccc', host.sanitize('aaa.bbb.xxx'))).toBe(false);
});

it('should allow underscore in host', function () {
const pattern = host.sanitize('*');
expect(host.test('aaa_bbb', pattern)).toBe(true);
});

});

});

0 comments on commit 94c33ca

Please sign in to comment.