Skip to content

Commit

Permalink
Merge 23eed1b into ebc0083
Browse files Browse the repository at this point in the history
  • Loading branch information
roottool committed May 3, 2019
2 parents ebc0083 + 23eed1b commit e05396d
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 36 deletions.
166 changes: 131 additions & 35 deletions src/addons/webLinks/webLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,63 +28,159 @@ describe('webLinks addon', () => {
});
});

it('should allow ~ character in URI path', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);
describe('should allow simple URI path', () => {
it('foo.com', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = ' http://foo.com/a~b#c~d?e~f ';
const row = ' http://foo.com ';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];
const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://foo.com/a~b#c~d?e~f');
assert.equal(uri, 'http://foo.com');
});

it('bar.io', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = ' http://bar.io ';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://bar.io');
});
});

it('should allow : character in URI path', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);
describe('should allow ~ character in URI path', () => {
it('foo.com', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = ' http://foo.com/a~b#c~d?e~f ';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://foo.com/a~b#c~d?e~f');
});

it('bar.io', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = ' http://foo.com/colon:test ';
const row = ' http://bar.io/a~b#c~d?e~f ';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];
const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://foo.com/colon:test');
assert.equal(uri, 'http://bar.io/a~b#c~d?e~f');
});
});

it('should not allow : character at the end of a URI path', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);
describe('should allow : character in URI path', () => {
it('foo.com', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = ' http://foo.com/colon:test ';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://foo.com/colon:test');
});

it('bar.io', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = ' http://foo.com/colon:test: ';
const row = ' http://bar.io/colon:test ';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];
const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://foo.com/colon:test');
assert.equal(uri, 'http://bar.io/colon:test');
});
});

it('should not allow " character at the end of a URI enclosed with ""', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);
describe('should not allow : character at the end of a URI path', () => {
it('foo.com', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = ' http://foo.com/colon:test: ';

const row = '"http://foo.com/"';
const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://foo.com/colon:test');
});

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];
it('bar.io', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

assert.equal(uri, 'http://foo.com/');
const row = ' http://bar.io/colon:test: ';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://bar.io/colon:test');
});
});

describe('should not allow " character at the end of a URI enclosed with ""', () => {
it('foo.com', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = '"http://foo.com/"';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://foo.com/');
});

it('bar.io', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = '"http://bar.io/"';

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://bar.io/');
});
});

it('should not allow \' character at the end of a URI enclosed with \'\'', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);
describe('should not allow \' character at the end of a URI enclosed with \'\'', () => {
it('foo.com', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = '\'http://foo.com/\'';

const row = '\'http://foo.com/\'';
const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

const match = row.match(term.regex);
const uri = match[term.options.matchIndex];
assert.equal(uri, 'http://foo.com/');
});

it('bar.io', () => {
const term = new MockTerminal();
webLinks.webLinksInit(<any>term);

const row = '\'http://bar.io/\'';

assert.equal(uri, 'http://foo.com/');
const match = row.match(term.regex);
const uri = match[term.options.matchIndex];

assert.equal(uri, 'http://bar.io/');
});
});
});
3 changes: 2 additions & 1 deletion src/addons/webLinks/webLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const ipClause = '((\\d{1,3}\\.){3}\\d{1,3})';
const localHostClause = '(localhost)';
const portClause = '(:\\d{1,5})';
const hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?';
const pathClause = '(\\/[\\/\\w\\.\\-%~:]*)*([^:"\'\\s])';
const pathCharacterSet = '(\\/[\\/\\w\\.\\-%~:]*)*([^:"\'\\s])';
const pathClause = '(' + pathCharacterSet + ')?';
const queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
const queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?';
const hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?';
Expand Down

0 comments on commit e05396d

Please sign in to comment.