Skip to content

Commit

Permalink
reverting invalid port processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 14, 2017
1 parent e985633 commit 236e765
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connection-string",
"version": "0.1.5",
"version": "0.1.6",
"description": "URL Connection String Parser.",
"main": "src/index.js",
"typings": "src/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
if (cs[0] !== '/') {
if (cs[0] === '[') {
// It is an IPv6, with [::] being the shortest possible
m = cs.match(/(\[([0-9a-z:%]{2,45})](?::([0-9]+)[?/]?$)?)/i);
m = cs.match(/(\[([0-9a-z:%]{2,45})](?::([0-9]+))?)/i);
} else {
// It is either IPv4 or a name
m = cs.match(/(([a-z0-9.-]*)(?::([0-9]+)[?/]?$)?)/i);
m = cs.match(/(([a-z0-9.-]*)(?::([0-9]+))?)/i);
}
if (m) {
if (m[1]) {
result.host = m[1].replace(/[/?]/, '');
result.host = m[1];
}
if (m[2]) {
result.hostname = m[2];
Expand Down
10 changes: 8 additions & 2 deletions test/mainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ describe('host', function () {
expect(parse('[a-b-c]')).toEqual({});
});
it('must ignore the invalid ports', function () {
expect(parse('[::]:1a')).toEqual({host: '[::]', hostname: '::'});
// TODO: consider adding, or not?
// expect(parse('[::]:1a')).toEqual({host: '[::]', hostname: '::'});
expect(parse('[::]:abc')).toEqual({host: '[::]', hostname: '::'});
});
it('must allow valid ports', function () {
Expand All @@ -145,12 +146,14 @@ describe('port', function () {
port: 0
});
});
// TODO: consider adding, or not?
/*
it('must not allow invalid terminators', function () {
expect(parse(':12345a')).toEqual({});
expect(parse('@:12345a')).toEqual({});
expect(parse(':abc')).toEqual({});
expect(parse('@:abc123')).toEqual({});
});
});*/
});

describe('segments', function () {
Expand Down Expand Up @@ -245,4 +248,7 @@ describe('complex', function () {
}
});
});
it('must not lose details after the port', function () {
expect(parse(':123/one')).toEqual({host: ':123', port: 123, segments: ['one']});
});
});

0 comments on commit 236e765

Please sign in to comment.