-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix URL parsing with paths that look like basic auth
- Loading branch information
1 parent
1354f3e
commit 4557ad1
Showing
4 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-env mocha */ | ||
|
||
var parseUri = require('../parseUri') | ||
var chai = require('chai') | ||
var expect = chai.expect | ||
|
||
describe('parseUri', function () { | ||
function assertURL (url, object) { | ||
expect(parseUri(url)).to.eql(object) | ||
} | ||
|
||
it('can parse a URL', function () { | ||
assertURL('http://localhost:1234/', { | ||
auth: '', | ||
authority: '//localhost:1234', | ||
hash: '', | ||
host: 'localhost:1234', | ||
hostname: 'localhost', | ||
href: 'http://localhost:1234/', | ||
pathname: '/', | ||
port: '1234', | ||
protocol: 'http:', | ||
search: '' | ||
}) | ||
}) | ||
|
||
it('can parse a URL with path and query', function () { | ||
assertURL('http://localhost:1234/a/path?a=A&b=B', { | ||
auth: '', | ||
authority: '//localhost:1234', | ||
hash: '', | ||
host: 'localhost:1234', | ||
hostname: 'localhost', | ||
href: 'http://localhost:1234/a/path?a=A&b=B', | ||
pathname: '/a/path', | ||
port: '1234', | ||
protocol: 'http:', | ||
search: '?a=A&b=B' | ||
}) | ||
}) | ||
|
||
it('can parse a URL with username and password', function () { | ||
assertURL('http://user%20name:pass%20word@localhost:1234/a/path?a=A&b=B', { | ||
auth: 'user name:pass word', | ||
authority: '//user%20name:pass%20word@localhost:1234', | ||
hash: '', | ||
host: 'localhost:1234', | ||
hostname: 'localhost', | ||
href: 'http://user%20name:pass%20word@localhost:1234/a/path?a=A&b=B', | ||
pathname: '/a/path', | ||
port: '1234', | ||
protocol: 'http:', | ||
search: '?a=A&b=B' | ||
}) | ||
}) | ||
|
||
it('can parse a URL with @ and : in the path', function () { | ||
assertURL('http://localhost:1234/a/path@with:isnotauth?a=A&b=B', { | ||
auth: '', | ||
authority: '//localhost:1234', | ||
hash: '', | ||
host: 'localhost:1234', | ||
hostname: 'localhost', | ||
href: 'http://localhost:1234/a/path@with:isnotauth?a=A&b=B', | ||
pathname: '/a/path@with:isnotauth', | ||
port: '1234', | ||
protocol: 'http:', | ||
search: '?a=A&b=B' | ||
}) | ||
}) | ||
}) |