Skip to content

Commit

Permalink
improving host parser
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 10, 2019
1 parent d2fdd84 commit 4e741bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,13 @@
if (!found) {
var obj = {};
if (h.name) {
obj.name = h.name;
if (h.type && h.type in hostType) {
obj.name = h.name;
obj.type = h.type;
} else {
var t = parseHost(h.name, true);
if (t) {
obj.name = t.name;
obj.type = t.type;
}
}
Expand Down
24 changes: 16 additions & 8 deletions test/mainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,6 @@ describe('setDefaults', () => {
port: 1
}]
});
expect(parse('my-host').setDefaults({hosts: [{name: '::', type: 'bla-bla'}]})).toEqual({
hosts: [{
name: 'my-host',
type: 'domain'
}, {
name: '::'
}]
});
expect(parse('my-host').setDefaults({hosts: [{name: 'my-host', port: 0}]})).toEqual({
hosts: [{
name: 'my-host',
Expand Down Expand Up @@ -537,6 +529,22 @@ describe('setDefaults', () => {
expect(parse('').setDefaults({hosts: [{name: 'abc'}]})).toEqual({hosts: [{name: 'abc', type: 'domain'}]});
expect(parse('').setDefaults({hosts: [{port: 123}]})).toEqual({hosts: [{port: 123}]});
});
it('must skip invalid hosts', () => {
expect(parse('my-host').setDefaults({hosts: [{name: '::'}]})).toEqual({
hosts: [{
name: 'my-host',
type: 'domain'
}]
});
// TODO: Invalid hosts must be skipped when parsed:
/*
expect(parse('').setDefaults({hosts: [{name: 'a b'}]})).toEqual({
hosts: [{
name: 'my-host',
type: 'domain'
}]
});*/
});
it('must ignore trailing spaces for host names', () => {
expect(parse('one').setDefaults({hosts: [{name: ' one '}]})).toEqual({
hosts: [{name: 'one', type: 'domain'}]
Expand Down

0 comments on commit 4e741bd

Please sign in to comment.