Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsuri

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsuri - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

test/uri/colonUri.js

5

package.json
{
"name": "jsuri",
"description": "Uri and query string manipulation",
"version": "1.3.0",
"version": "1.3.1",
"author": "Derek Watson <watson@dcw.ca> (http://dcw.ca)",

@@ -34,4 +34,3 @@ "contributors": [

"uglify-js": "~2.4.0",
"mocha": "~1.14.0",
"chai": "~1.9.2"
"mocha": "~1.14.0"
},

@@ -38,0 +37,0 @@ "optionalDependencies": {},

@@ -115,2 +115,12 @@ # jsUri

Test for the existence of query parameters named `key`:
```js
new Uri('?a=1&b=2&c=3')
.hasQueryParam('a') // true
new Uri('?a=1&b=2&c=3')
.hasQueryParam('d') // false
```
Create an identical URI object with no shared state:

@@ -117,0 +127,0 @@

96

test/uri.js

@@ -1,2 +0,2 @@

var expect = require('chai').expect
var assert = require("assert")

@@ -14,3 +14,3 @@ var Uri = (typeof(require) === 'function') ? require('../Uri') : window.Uri

u.protocol('https')
expect(u.toString()).to.equal('https://test.com')
assert.equal(u.toString(), 'https://test.com');
})

@@ -20,3 +20,3 @@

u.protocol('https:')
expect(u.toString()).to.equal('https://test.com')
assert.equal(u.toString(), 'https://test.com')
})

@@ -26,3 +26,3 @@

u.protocol(null)
expect(u.toString()).to.equal('//test.com')
assert.equal(u.toString(), '//test.com')
})

@@ -32,3 +32,3 @@

u.hasAuthorityPrefix(false)
expect(u.toString()).to.equal('http://test.com')
assert.equal(u.toString(), 'http://test.com')
})

@@ -38,3 +38,3 @@

u.userInfo('username:password')
expect(u.toString()).to.equal('http://username:password@test.com')
assert.equal(u.toString(), 'http://username:password@test.com')
})

@@ -44,3 +44,3 @@

u.userInfo('username:password@')
expect(u.toString()).to.equal('http://username:password@test.com')
assert.equal(u.toString(), 'http://username:password@test.com')
})

@@ -51,3 +51,3 @@

u.host('wherever.com')
expect(u.toString()).to.equal('wherever.com/index.html')
assert.equal(u.toString(), 'wherever.com/index.html')
})

@@ -57,3 +57,3 @@

u.host('wherever.com')
expect(u.toString()).to.equal('http://wherever.com')
assert.equal(u.toString(), 'http://wherever.com')
})

@@ -64,3 +64,3 @@

u.port(8080)
expect(u.toString()).to.equal('/index.html')
assert.equal(u.toString(), '/index.html')
})

@@ -70,3 +70,3 @@

u.port(8080)
expect(u.toString()).to.equal('http://test.com:8080')
assert.equal(u.toString(), 'http://test.com:8080')
})

@@ -77,3 +77,3 @@

u.path('/some/article.html')
expect(u.toString()).to.equal('test.com/some/article.html')
assert.equal(u.toString(), 'test.com/some/article.html')
})

@@ -83,3 +83,3 @@

u.path('/some/article.html')
expect(u.toString()).to.equal('http://test.com/some/article.html')
assert.equal(u.toString(), 'http://test.com/some/article.html')
})

@@ -90,3 +90,3 @@

u.path(null)
expect(u.toString()).to.equal('http://test.com')
assert.equal(u.toString(), 'http://test.com')
})

@@ -97,3 +97,3 @@

u.path('')
expect(u.toString()).to.equal('http://test.com')
assert.equal(u.toString(), 'http://test.com')
})

@@ -104,3 +104,3 @@

u.query('this=that&something=else')
expect(u.toString()).to.equal('?this=that&something=else')
assert.equal(u.toString(), '?this=that&something=else')
})

@@ -111,3 +111,3 @@

u.query('this=that&something=else')
expect(u.toString()).to.equal('/some/file.html?this=that&something=else')
assert.equal(u.toString(), '/some/file.html?this=that&something=else')
})

@@ -118,3 +118,3 @@

u.query('this=that&something=else')
expect(u.toString()).to.equal('test.com/?this=that&something=else')
assert.equal(u.toString(), 'test.com/?this=that&something=else')
})

@@ -125,3 +125,3 @@

u.query('this=that&something=else')
expect(u.toString()).to.equal('www.test.com/?this=that&something=else')
assert.equal(u.toString(), 'www.test.com/?this=that&something=else')
})

@@ -132,3 +132,3 @@

u.query(null)
expect(u.toString()).to.equal('www.test.com')
assert.equal(u.toString(), 'www.test.com')
})

@@ -139,3 +139,3 @@

u.query('')
expect(u.toString()).to.equal('www.test.com')
assert.equal(u.toString(), 'www.test.com')
})

@@ -146,3 +146,3 @@

u.anchor('content')
expect(u.toString()).to.equal('test.com/#content')
assert.equal(u.toString(), 'test.com/#content')
})

@@ -153,3 +153,3 @@

u.anchor('#content')
expect(u.toString()).to.equal('test.com/#content')
assert.equal(u.toString(), 'test.com/#content')
})

@@ -160,3 +160,3 @@

u.anchor('content')
expect(u.toString()).to.equal('a/b/c/123.html#content')
assert.equal(u.toString(), 'a/b/c/123.html#content')
})

@@ -167,3 +167,3 @@

u.anchor('about')
expect(u.toString()).to.equal('/a/b/c/index.html#about')
assert.equal(u.toString(), '/a/b/c/index.html#about')
})

@@ -174,3 +174,3 @@

u.anchor('')
expect(u.toString()).to.equal('/a/b/c/index.html')
assert.equal(u.toString(), '/a/b/c/index.html')
})

@@ -181,3 +181,3 @@

u.anchor(null)
expect(u.toString()).to.equal('/a/b/c/index.html')
assert.equal(u.toString(), '/a/b/c/index.html')
})

@@ -187,3 +187,3 @@

u = new Uri('http://example.com/search?q=%40')
expect(u.getQueryParamValue('q')).to.equal('@')
assert.equal(u.getQueryParamValue('q'), '@')
})

@@ -193,3 +193,3 @@

u = new Uri('http://example.com/search?q=%2540')
expect(u.getQueryParamValue('q')).to.equal('%40')
assert.equal(u.getQueryParamValue('q'), '%40')
})

@@ -200,3 +200,3 @@

u.deleteQueryParam('stupid')
expect(u.toString()).to.equal('http://example.com/search?q=%40')
assert.equal(u.toString(), 'http://example.com/search?q=%40')
})

@@ -207,3 +207,3 @@

u.deleteQueryParam('stupid')
expect(u.toString()).to.equal('http://example.com/search?q=100%25')
assert.equal(u.toString(), 'http://example.com/search?q=100%25')
})

@@ -214,3 +214,3 @@

u.setPath('relativePath')
expect(u.toString()).to.equal('http://test.com/relativePath')
assert.equal(u.toString(), 'http://test.com/relativePath')
})

@@ -221,3 +221,3 @@

u.setPath('/relativePath')
expect(u.toString()).to.equal('http://test.com/relativePath')
assert.equal(u.toString(), 'http://test.com/relativePath')
})

@@ -228,3 +228,3 @@

u.setPath('//relativePath')
expect(u.toString()).to.equal('http://test.com/relativePath')
assert.equal(u.toString(), 'http://test.com/relativePath')
})

@@ -235,3 +235,3 @@

b = a.clone().addQueryParam('b', '2')
expect(a.toString()).to.not.equal(b.toString())
assert.notEqual(a.toString(), b.toString())
})

@@ -243,3 +243,3 @@

.toString()
expect(str).to.equal('http://www.example.com/path/?arr=1&arr=2')
assert.equal(str, 'http://www.example.com/path/?arr=1&arr=2')
})

@@ -250,3 +250,3 @@

var uri = new Uri(str)
expect(uri.toString()).to.equal(str)
assert.equal(uri.toString(), str)
})

@@ -257,4 +257,24 @@

var parsed = new Uri('http://example.com' + originalQuery)
expect(parsed.query()).to.equal(originalQuery)
assert.equal(parsed.query(), originalQuery)
})
it('parse + character correctly', function() {
var parsed = new Uri('http://example.com?test=a%2Bb')
assert.equal(parsed.toString(), 'http://example.com/?test=a%2Bb')
})
it('Read + character correctly', function() {
var test = new Uri('http://example.com?test=a%2Bb').getQueryParamValue('test')
assert.equal(test, 'a+b')
})
it('parse space character encoded as + correctly', function() {
var parsed = new Uri('http://example.com?test=a+b')
assert.equal(parsed.toString(), 'http://example.com/?test=a%20b')
})
it('Read parsed space character encoded as + correctly', function() {
var test = new Uri('http://example.com?test=a+b').getQueryParamValue('test')
assert.equal(test, 'a b')
})
})

@@ -1,2 +0,2 @@

var expect = require('chai').expect
var assert = require("assert");

@@ -13,3 +13,3 @@ var Uri = (typeof(require) === 'function') ? require('../../Uri') : window.Uri

.setAnchor('content')
expect(u.toString()).to.equal('www.yahoo.com/index.html#content')
assert.equal(u.toString(), 'www.yahoo.com/index.html#content')
})

@@ -21,3 +21,3 @@

.setProtocol('https')
expect(u.toString()).to.equal('https://test.com/index.html')
assert.equal(u.toString(), 'https://test.com/index.html')
})

@@ -34,3 +34,3 @@

.setQuery('this=that&some=thing')
expect(u.toString()).to.equal('https://username:password@www.test.com:8080/index.html?this=that&some=thing#content')
assert.equal(u.toString(), 'https://username:password@www.test.com:8080/index.html?this=that&some=thing#content')
})

@@ -47,5 +47,5 @@

.setQuery(null)
expect(u.toString()).to.equal('')
assert.equal(u.toString(), '')
})
})
})

@@ -1,2 +0,2 @@

var expect = require('chai').expect
var assert = require('assert');

@@ -10,3 +10,3 @@ var Uri = (typeof(require) === 'function') ? require('../../Uri') : window.Uri

var back = new Uri('?back=path/to/list?page=1').getQueryParamValue('back')
expect(back).to.equal('path/to/list?page=1')
assert.equal(back, 'path/to/list?page=1')
})

@@ -19,3 +19,3 @@

q = new Uri('?email=user%40example.com')
expect(q.getQueryParamValue('email')).to.equal('user@example.com')
assert.equal(q.getQueryParamValue('email'), 'user@example.com')
})

@@ -25,3 +25,3 @@

q = new Uri('?11=')
expect(q.toString()).to.equal('?11=')
assert.equal(q.toString(), '?11=')
})

@@ -31,3 +31,3 @@

q = new Uri('?11')
expect(q.toString()).to.equal('?11')
assert.equal(q.toString(), '?11')
})

@@ -37,3 +37,3 @@

q = new Uri('?11&12&13&14')
expect(q.toString()).to.equal('?11&12&13&14')
assert.equal(q.toString(), '?11&12&13&14')
})

@@ -43,3 +43,3 @@

q = new Uri('?11=eleven&12=&13&14=fourteen')
expect(q.toString()).to.equal('?11=eleven&12=&13&14=fourteen')
assert.equal(q.toString(), '?11=eleven&12=&13&14=fourteen')
})

@@ -49,6 +49,6 @@

q = new Uri('http://github.com/username?email=user@example.com&11=eleven')
expect(q.host()).to.equal('github.com')
expect(q.path()).to.equal('/username')
expect(q.getQueryParamValue('email')).to.equal('user@example.com')
expect(q.getQueryParamValue('11')).to.equal('eleven')
assert.equal(q.host(), 'github.com')
assert.equal(q.path(), '/username')
assert.equal(q.getQueryParamValue('email'), 'user@example.com')
assert.equal(q.getQueryParamValue('11'), 'eleven')
})

@@ -62,5 +62,5 @@ })

q = new Uri('?a=1&a=2&b=3&b=4&c=567')
expect(q.getQueryParamValue('a')).to.equal('1')
expect(q.getQueryParamValue('b')).to.equal('3')
expect(q.getQueryParamValue('c')).to.equal('567')
assert.equal(q.getQueryParamValue('a'), '1')
assert.equal(q.getQueryParamValue('b'), '3')
assert.equal(q.getQueryParamValue('c'), '567')
})

@@ -70,7 +70,7 @@

q = new Uri('?a=1&a=2&b=3&b=4&c=567')
expect(q.getQueryParamValues('a')[0]).to.equal('1')
expect(q.getQueryParamValues('a')[1]).to.equal('2')
expect(q.getQueryParamValues('b')[0]).to.equal('3')
expect(q.getQueryParamValues('b')[1]).to.equal('4')
expect(q.getQueryParamValues('c')[0]).to.equal('567')
assert.equal(q.getQueryParamValues('a')[0], '1')
assert.equal(q.getQueryParamValues('a')[1], '2')
assert.equal(q.getQueryParamValues('b')[0], '3')
assert.equal(q.getQueryParamValues('b')[1], '4')
assert.equal(q.getQueryParamValues('c')[0], '567')
})

@@ -80,8 +80,13 @@

q = new Uri('').addQueryParam('q', 'books')
expect(q.toString()).to.equal('?q=books')
assert.equal(q.toString(), '?q=books')
})
it('can add a query param with a value of zero', function() {
q = new Uri('').addQueryParam('pg', 0)
assert.equal(q.toString(), '?pg=0')
})
it('should be able to delete a query param', function() {
q = new Uri('?a=1&b=2&c=3&a=eh').deleteQueryParam('b')
expect(q.toString()).to.equal('?a=1&c=3&a=eh')
assert.equal(q.toString(), '?a=1&c=3&a=eh')
})

@@ -91,3 +96,3 @@

q = new Uri('?a=1&b=2&c=3&a=eh').deleteQueryParam('a', 'eh')
expect(q.toString()).to.equal('?a=1&b=2&c=3')
assert.equal(q.toString(), '?a=1&b=2&c=3')
})

@@ -97,3 +102,3 @@

q = new Uri('?a=1&b=2&c=3').addQueryParam('d')
expect(q.toString()).to.equal('?a=1&b=2&c=3&d=')
assert.equal(q.toString(), '?a=1&b=2&c=3&d=')
})

@@ -103,3 +108,3 @@

q = new Uri('?a=1&b=2&c=3').addQueryParam('d', '4')
expect(q.toString()).to.equal('?a=1&b=2&c=3&d=4')
assert.equal(q.toString(), '?a=1&b=2&c=3&d=4')
})

@@ -109,3 +114,3 @@

q = new Uri('?a=1&b=2&c=3').addQueryParam('d', '4', 0)
expect(q.toString()).to.equal('?d=4&a=1&b=2&c=3')
assert.equal(q.toString(), '?d=4&a=1&b=2&c=3')
})

@@ -115,3 +120,3 @@

q = new Uri('').addQueryParam('k', 'value@example.com')
expect(q.getQueryParamValue('k')).to.equal('value@example.com')
assert.equal(q.getQueryParamValue('k'), 'value@example.com')
})

@@ -121,3 +126,3 @@

q = new Uri('http://example.com').addQueryParam('k', 'user@example.org')
expect(q.toString()).to.equal('http://example.com/?k=user%40example.org')
assert.equal(q.toString(), 'http://example.com/?k=user%40example.org')
})

@@ -127,3 +132,3 @@

q = new Uri('?a=1&b=2&c=3').deleteQueryParam('a').addQueryParam('a', 'eh')
expect(q.toString()).to.equal('?b=2&c=3&a=eh')
assert.equal(q.toString(), '?b=2&c=3&a=eh')
})

@@ -133,3 +138,3 @@

q = new Uri('?a=1&b=2&c=3').addQueryParam()
expect(q.toString()).to.equal('?a=1&b=2&c=3')
assert.equal(q.toString(), '?a=1&b=2&c=3')
})

@@ -139,3 +144,3 @@

q = new Uri('?a=1&b=2&c=3').replaceQueryParam('a', 'eh')
expect(q.toString()).to.equal('?a=eh&b=2&c=3')
assert.equal(q.toString(), '?a=eh&b=2&c=3')
})

@@ -145,3 +150,3 @@

q = new Uri('??a=1&b=2&c=3').replaceQueryParam('a', 4)
expect(q.toString()).to.equal('?a=4&b=2&c=3')
assert.equal(q.toString(), '?a=4&b=2&c=3')
})

@@ -151,3 +156,3 @@

q = new Uri('?=1&b=2&c=3').replaceQueryParam('a', 4)
expect(q.toString()).to.equal('?b=2&c=3&a=4')
assert.equal(q.toString(), '?b=2&c=3&a=4')
})

@@ -157,3 +162,3 @@

q = new Uri().replaceQueryParam('page', 2)
expect(q.toString()).to.equal('?page=2')
assert.equal(q.toString(), '?page=2')
})

@@ -163,3 +168,3 @@

q = new Uri('?a=1').replaceQueryParam('page', 2)
expect(q.toString()).to.equal('?a=1&page=2')
assert.equal(q.toString(), '?a=1&page=2')
})

@@ -169,3 +174,3 @@

q = new Uri('?page=1&page=2').replaceQueryParam('page', 3, 1)
expect(q.toString()).to.equal('?page=3&page=2')
assert.equal(q.toString(), '?page=3&page=2')
})

@@ -175,3 +180,3 @@

q = new Uri('?a=one&a=two').replaceQueryParam('a', 'three', 'one')
expect(q.toString()).to.equal('?a=three&a=two')
assert.equal(q.toString(), '?a=three&a=two')
})

@@ -181,3 +186,3 @@

q = new Uri('?page=4&page=2').replaceQueryParam('page', 3, 1)
expect(q.toString()).to.equal('?page=4&page=2')
assert.equal(q.toString(), '?page=4&page=2')
})

@@ -187,3 +192,3 @@

q = new Uri('?page=4&page=2').replaceQueryParam('page')
expect(q.toString()).to.equal('?page=')
assert.equal(q.toString(), '?page=')
})

@@ -193,16 +198,16 @@

q = new Uri().addQueryParam('a', 1)
expect(q.toString()).to.equal('?a=1')
expect(q.getQueryParamValues('a').length).to.equal(1)
assert.equal(q.toString(), '?a=1')
assert.equal(q.getQueryParamValues('a').length, 1)
q.addQueryParam('a', 2)
expect(q.toString()).to.equal('?a=1&a=2')
expect(q.getQueryParamValues('a').length).to.equal(2)
assert.equal(q.toString(), '?a=1&a=2')
assert.equal(q.getQueryParamValues('a').length, 2)
q.addQueryParam('a', 3)
expect(q.toString()).to.equal('?a=1&a=2&a=3')
expect(q.getQueryParamValues('a').length).to.equal(3)
assert.equal(q.toString(), '?a=1&a=2&a=3')
assert.equal(q.getQueryParamValues('a').length, 3)
q.deleteQueryParam('a', 2)
expect(q.toString()).to.equal('?a=1&a=3')
expect(q.getQueryParamValues('a').length).to.equal(2)
assert.equal(q.toString(), '?a=1&a=3')
assert.equal(q.getQueryParamValues('a').length, 2)
q.deleteQueryParam('a')
expect(q.toString()).to.equal('')
expect(q.getQueryParamValues('a').length).to.equal(0)
assert.equal(q.toString(), '')
assert.equal(q.getQueryParamValues('a').length, 0)
})

@@ -212,3 +217,3 @@

q = new Uri('stuff/').addTrailingSlash();
expect(q.toString()).to.equal('stuff/')
assert.equal(q.toString(), 'stuff/')
})

@@ -218,3 +223,3 @@

q = new Uri().addTrailingSlash();
expect(q.toString()).to.equal('/')
assert.equal(q.toString(), '/')
})

@@ -228,3 +233,3 @@ })

q = new Uri('?one=1;two=2;three=3')
expect(q.toString()).to.equal('?one=1&two=2&three=3')
assert.equal(q.toString(), '?one=1&two=2&three=3')
})

@@ -234,3 +239,3 @@

q = new Uri('?one=1;two=2;three=3&four=4').deleteQueryParam('one').addQueryParam('test', 'val', 1)
expect(q.toString()).to.equal('?two=2&test=val&three=3&four=4')
assert.equal(q.toString(), '?two=2&test=val&three=3&four=4')
})

@@ -244,3 +249,3 @@ })

q = new Uri('?a=1&this%20is%20a%20multiword%20key=value&c=3')
expect(q.getQueryParamValue('this is a multiword key')).to.equal('value')
assert.equal(q.getQueryParamValue('this is a multiword key'), 'value')
})

@@ -250,3 +255,3 @@

q = new Uri('?a=1&b=this%20is%20a%20multiword%20val&c=3')
expect(q.getQueryParamValue('b')).to.equal('this is a multiword val')
assert.equal(q.getQueryParamValue('b'), 'this is a multiword val')
})

@@ -256,3 +261,3 @@

q = new Uri('?a=1&b=this is a multiword value&c=3')
expect(q.getQueryParamValue('b')).to.equal('this is a multiword value')
assert.equal(q.getQueryParamValue('b'), 'this is a multiword value')
})

@@ -262,3 +267,3 @@

q = new Uri('?a=1&b=this%2520is%2520a%2520multiword%2520value&c=3')
expect(q.getQueryParamValue('b')).to.equal('this%20is%20a%20multiword%20value')
assert.equal(q.getQueryParamValue('b'), 'this%20is%20a%20multiword%20value')
})

@@ -268,3 +273,3 @@

q = new Uri('?a=1&this%20is%20a%20multiword%20key=value&c=3')
expect(q.getQueryParamValues('this is a multiword key')[0]).to.equal('value')
assert.equal(q.getQueryParamValues('this is a multiword key')[0], 'value')
})

@@ -274,3 +279,3 @@

q = new Uri('?a=1&this%20is%20a%20multiword%20key=value&c=3').deleteQueryParam('this is a multiword key')
expect(q.toString()).to.equal('?a=1&c=3')
assert.equal(q.toString(), '?a=1&c=3')
})

@@ -280,3 +285,3 @@

q = new Uri('?this is a multiword key=1').replaceQueryParam('this%20is%20a%20multiword%20key', 2)
expect(q.toString()).to.equal('?this%20is%20a%20multiword%20key=2')
assert.equal(q.toString(), '?this%20is%20a%20multiword%20key=2')
})

@@ -286,6 +291,12 @@

q = new Uri('?multi+word+key=true').replaceQueryParam('multi word key', 2)
expect(q.toString()).to.equal('?multi word key=2')
assert.equal(q.toString(), '?multi word key=2')
})
})
describe('testing for the existence of query params', function() {
q = new Uri('?this=that')
assert(q.hasQueryParam('this'))
assert(!q.hasQueryParam('theother'))
})
})
})

@@ -1,2 +0,2 @@

var expect = require('chai').expect
var assert = require('assert');

@@ -8,109 +8,109 @@ var Uri = (typeof(require) === 'function') ? require('../../Uri') : window.Uri

it('should convert empty constructor call to blank url', function() {
expect(new Uri().toString()).to.equal('')
assert.equal(new Uri().toString(), '')
})
it('can construct empty string', function() {
expect(new Uri().toString()).to.equal('')
assert.equal(new Uri().toString(), '')
})
it('can construct single slash', function() {
expect(new Uri('/').toString()).to.equal('/')
assert.equal(new Uri('/').toString(), '/')
})
it('can construct a relative path with a trailing slash', function() {
expect(new Uri('tutorial1/').toString()).to.equal('tutorial1/')
assert.equal(new Uri('tutorial1/').toString(), 'tutorial1/')
})
it('can construct a relative path with leading and trailing slashes', function() {
expect(new Uri('/experts/').toString()).to.equal('/experts/')
assert.equal(new Uri('/experts/').toString(), '/experts/')
})
it('can construct a relative filename with leading slash', function() {
expect(new Uri('/index.html').toString()).to.equal('/index.html')
assert.equal(new Uri('/index.html').toString(), '/index.html')
})
it('can construct a relative directory and filename', function() {
expect(new Uri('tutorial1/2.html').toString()).to.equal('tutorial1/2.html')
assert.equal(new Uri('tutorial1/2.html').toString(), 'tutorial1/2.html')
})
it('can construct a relative parent directory', function() {
expect(new Uri('../').toString()).to.equal('../')
assert.equal(new Uri('../').toString(), '../')
})
it('can construct a relative great grandparent directory', function() {
expect(new Uri('../../../').toString()).to.equal('../../../')
assert.equal(new Uri('../../../').toString(), '../../../')
})
it('can construct a relative current directory', function() {
expect(new Uri('./').toString()).to.equal('./')
assert.equal(new Uri('./').toString(), './')
})
it('can construct a relative current directory sibling doc', function() {
expect(new Uri('./index.html').toString()).to.equal('./index.html')
assert.equal(new Uri('./index.html').toString(), './index.html')
})
it('can construct a simple three level domain', function() {
expect(new Uri('www.example.com').toString()).to.equal('www.example.com')
assert.equal(new Uri('www.example.com').toString(), 'www.example.com')
})
it('can construct a simple absolute url', function() {
expect(new Uri('http://www.example.com/index.html').toString()).to.equal('http://www.example.com/index.html')
assert.equal(new Uri('http://www.example.com/index.html').toString(), 'http://www.example.com/index.html')
})
it('can construct a secure absolute url', function() {
expect(new Uri('https://www.example.com/index.html').toString()).to.equal('https://www.example.com/index.html')
assert.equal(new Uri('https://www.example.com/index.html').toString(), 'https://www.example.com/index.html')
})
it('can construct a simple url with a custom port', function() {
expect(new Uri('http://www.example.com:8080/index.html').toString()).to.equal('http://www.example.com:8080/index.html')
assert.equal(new Uri('http://www.example.com:8080/index.html').toString(), 'http://www.example.com:8080/index.html')
})
it('can construct a secure url with a custom port', function() {
expect(new Uri('https://www.example.com:4433/index.html').toString()).to.equal('https://www.example.com:4433/index.html')
assert.equal(new Uri('https://www.example.com:4433/index.html').toString(), 'https://www.example.com:4433/index.html')
})
it('can construct a relative path with a hash part', function() {
expect(new Uri('/index.html#about').toString()).to.equal('/index.html#about')
assert.equal(new Uri('/index.html#about').toString(), '/index.html#about')
})
it('can construct a relative path with a hash part', function() {
expect(new Uri('/index.html#about').toString()).to.equal('/index.html#about')
assert.equal(new Uri('/index.html#about').toString(), '/index.html#about')
})
it('can construct an absolute path with a hash part', function() {
expect(new Uri('http://example.com/index.html#about').toString()).to.equal('http://example.com/index.html#about')
assert.equal(new Uri('http://example.com/index.html#about').toString(), 'http://example.com/index.html#about')
})
it('can construct a relative path with a query string', function() {
expect(new Uri('/index.html?a=1&b=2').toString()).to.equal('/index.html?a=1&b=2')
assert.equal(new Uri('/index.html?a=1&b=2').toString(), '/index.html?a=1&b=2')
})
it('can construct an absolute path with a query string', function() {
expect(new Uri('http://www.test.com/index.html?a=1&b=2').toString()).to.equal('http://www.test.com/index.html?a=1&b=2')
assert.equal(new Uri('http://www.test.com/index.html?a=1&b=2').toString(), 'http://www.test.com/index.html?a=1&b=2')
})
it('can construct an absolute path with a query string and hash', function() {
expect(new Uri('http://www.test.com/index.html?a=1&b=2#a').toString()).to.equal('http://www.test.com/index.html?a=1&b=2#a')
assert.equal(new Uri('http://www.test.com/index.html?a=1&b=2#a').toString(), 'http://www.test.com/index.html?a=1&b=2#a')
})
it('can construct a url with multiple synonymous query values', function() {
expect(new Uri('http://www.test.com/index.html?arr=1&arr=2&arr=3&arr=3&b=2').toString()).to.equal('http://www.test.com/index.html?arr=1&arr=2&arr=3&arr=3&b=2')
assert.equal(new Uri('http://www.test.com/index.html?arr=1&arr=2&arr=3&arr=3&b=2').toString(), 'http://www.test.com/index.html?arr=1&arr=2&arr=3&arr=3&b=2')
})
it('can construct a url with blank query value', function() {
expect(new Uri('http://www.test.com/index.html?arr=1&arr=&arr=2').toString()).to.equal('http://www.test.com/index.html?arr=1&arr=&arr=2')
assert.equal(new Uri('http://www.test.com/index.html?arr=1&arr=&arr=2').toString(), 'http://www.test.com/index.html?arr=1&arr=&arr=2')
})
it('can construct a url without a scheme', function() {
expect(new Uri('//www.test.com/').toString()).to.equal('//www.test.com/')
assert.equal(new Uri('//www.test.com/').toString(), '//www.test.com/')
})
it('can construct a path and single query kvp', function() {
expect(new Uri('/contacts?name=m').toString()).to.equal('/contacts?name=m')
assert.equal(new Uri('/contacts?name=m').toString(), '/contacts?name=m')
})
it('returns successfully returns the origin with a scheme, auth, host and port', function() {
expect(new Uri('http://me:here@test.com:81/this/is/a/path').origin()).to.equal('http://me:here@test.com:81')
assert.equal(new Uri('http://me:here@test.com:81/this/is/a/path').origin(), 'http://me:here@test.com:81')
})
})
})

@@ -23,3 +23,3 @@ /*!

query_separator: /[&;]/,
uri_parser: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
uri_parser: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*)(?::([^:@]*))?)?@)?(\[[0-9a-fA-F:.]+\]|[^:\/?#]*)(?::(\d+|(?=:)))?(:)?)((((?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
};

@@ -70,4 +70,4 @@

if (s) {
s = decodeURIComponent(s);
s = s.replace(re.pluses, ' ');
s = s.toString().replace(re.pluses, '%20');
s = decodeURIComponent(s);
}

@@ -84,3 +84,3 @@ return s;

var parser = re.uri_parser;
var parserKeys = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"];
var parserKeys = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "isColonUri", "relative", "path", "directory", "file", "query", "anchor"];
var m = parser.exec(str || '');

@@ -102,3 +102,3 @@ var parts = {};

function parseQuery(str) {
var i, ps, p, n, k, v;
var i, ps, p, n, k, v, l;
var pairs = [];

@@ -121,4 +121,4 @@

if (n !== 0) {
k = decodeURIComponent(p.substring(0, n));
v = decodeURIComponent(p.substring(n + 1));
k = decode(p.substring(0, n));
v = decode(p.substring(n + 1));
pairs.push(n === -1 ? [p, null] : [k, v]);

@@ -171,2 +171,10 @@ }

Uri.prototype.isColonUri = function (val) {
if (typeof val !== 'undefined') {
this.uriParts.isColonUri = !!val;
} else {
return !!this.uriParts.isColonUri;
}
};
/**

@@ -178,3 +186,3 @@ * Serializes the internal state of the query pairs

Uri.prototype.query = function(val) {
var s = '', i, param;
var s = '', i, param, l;

@@ -195,3 +203,3 @@ if (typeof val !== 'undefined') {

s += '=';
if (param[1]) {
if (typeof param[1] !== 'undefined') {
s += encodeURIComponent(param[1]);

@@ -210,3 +218,3 @@ }

Uri.prototype.getQueryParamValue = function (key) {
var param, i;
var param, i, l;
for (i = 0, l = this.queryPairs.length; i < l; i++) {

@@ -226,3 +234,3 @@ param = this.queryPairs[i];

Uri.prototype.getQueryParamValues = function (key) {
var arr = [], i, param;
var arr = [], i, param, l;
for (i = 0, l = this.queryPairs.length; i < l; i++) {

@@ -244,3 +252,3 @@ param = this.queryPairs[i];

Uri.prototype.deleteQueryParam = function (key, val) {
var arr = [], i, param, keyMatchesFilter, valMatchesFilter;
var arr = [], i, param, keyMatchesFilter, valMatchesFilter, l;

@@ -281,2 +289,18 @@ for (i = 0, l = this.queryPairs.length; i < l; i++) {

/**
* test for the existence of a query parameter
* @param {string} key add values for key
* @param {string} val value to add
* @param {integer} [index] specific index to add the value at
* @return {Uri} returns self for fluent chaining
*/
Uri.prototype.hasQueryParam = function (key) {
var i, len = this.queryPairs.length;
for (i = 0; i < len; i++) {
if (this.queryPairs[i][0] == key)
return true;
}
return false;
};
/**
* replaces query param values

@@ -319,3 +343,3 @@ * @param {string} key key to replace value for

*/
['protocol', 'hasAuthorityPrefix', 'userInfo', 'host', 'port', 'path', 'query', 'anchor'].forEach(function(key) {
['protocol', 'hasAuthorityPrefix', 'isColonUri', 'userInfo', 'host', 'port', 'path', 'query', 'anchor'].forEach(function(key) {
var method = 'set' + key.charAt(0).toUpperCase() + key.slice(1);

@@ -358,6 +382,2 @@ Uri.prototype[method] = function(val) {

if (s == 'file://') {
return s + this.uriParts.authority;
}
if (this.userInfo() && this.host()) {

@@ -372,3 +392,3 @@ s += this.userInfo();

s += this.host();
if (this.port()) {
if (this.port() || (this.path() && this.path().substr(0, 1).match(/[0-9]/))) {
s += ':' + this.port();

@@ -401,3 +421,7 @@ }

if (this.path()) {
if (this.isColonUri()) {
if (this.path()) {
s += ':'+this.path();
}
} else if (this.path()) {
path = this.path();

@@ -419,5 +443,2 @@ if (!(re.ends_with_slashes.test(s) || re.starts_with_slashes.test(path))) {

if (this.query().toString()) {
if (this.query().toString().indexOf('?') !== 0) {
s += '?';
}
s += this.query().toString();

@@ -424,0 +445,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc