urlparse-template
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -15,5 +15,7 @@ var ut = require('url-template'), | ||
var authParts = res.auth.split(':'); | ||
if (authParts.length >= 2) { | ||
if (authParts.length > 0) { | ||
res.username = authParts.shift(); | ||
res.password = authParts.join(':'); | ||
if (authParts.length > 0) { | ||
res.password = authParts.join(':'); | ||
} | ||
} | ||
@@ -20,0 +22,0 @@ } |
{ | ||
"name": "urlparse-template", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Template-based URL-parsing", | ||
@@ -22,4 +22,4 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"chai": "~1.6.0", | ||
"mocha": "~1.10.0" | ||
"mocha": "~1.10.0", | ||
"unexpected": "^10.15.0" | ||
}, | ||
@@ -26,0 +26,0 @@ "dependencies": { |
@@ -1,2 +0,2 @@ | ||
var assert = require('chai').assert, | ||
var expect = require('unexpected'), | ||
p = require('../'); | ||
@@ -7,18 +7,17 @@ | ||
var t = p('proto://{username}:pwd@{sub}.domain.tld'); | ||
assert.isFunction(t); | ||
assert.lengthOf(t, 1); | ||
expect(t, 'to be a function').and('to have arity', 1); | ||
// Fill the tempalte | ||
var d = t({username: '123', sub: '456'}); | ||
assert.isObject(d); | ||
assert.propertyVal(d, 'auth', '123:pwd'); | ||
assert.propertyVal(d, 'host', '456.domain.tld'); | ||
assert.propertyVal(d, 'hostname', '456.domain.tld'); | ||
assert.propertyVal(d, 'href', 'proto://123:pwd@456.domain.tld'); | ||
assert.propertyVal(d, 'password', 'pwd'); | ||
assert.propertyVal(d, 'protocol', 'proto:'); | ||
assert.propertyVal(d, 'slashes', true); | ||
assert.propertyVal(d, 'username', '123'); | ||
expect(t({username: '123', sub: '456'}), 'to satisfy', { | ||
auth: '123:pwd', | ||
host: '456.domain.tld', | ||
hostname: '456.domain.tld', | ||
href: 'proto://123:pwd@456.domain.tld', | ||
password: 'pwd', | ||
protocol: 'proto:', | ||
slashes: true, | ||
username: '123' | ||
}); | ||
}); | ||
it('Two parameters invokes it directly', function () { | ||
@@ -30,35 +29,54 @@ var d = p( | ||
assert.isObject(d); | ||
assert.propertyVal(d, 'auth', '123:pwd'); | ||
assert.propertyVal(d, 'host', '456.domain.tld'); | ||
assert.propertyVal(d, 'hostname', '456.domain.tld'); | ||
assert.propertyVal(d, 'href', 'proto://123:pwd@456.domain.tld'); | ||
assert.propertyVal(d, 'password', 'pwd'); | ||
assert.propertyVal(d, 'protocol', 'proto:'); | ||
assert.propertyVal(d, 'slashes', true); | ||
assert.propertyVal(d, 'username', '123'); | ||
expect(d, 'to satisfy', { | ||
auth: '123:pwd', | ||
host: '456.domain.tld', | ||
hostname: '456.domain.tld', | ||
href: 'proto://123:pwd@456.domain.tld', | ||
password: 'pwd', | ||
protocol: 'proto:', | ||
slashes: true, | ||
username: '123' | ||
}); | ||
}); | ||
}); | ||
it('should populate the username field even when there is no password', function () { | ||
expect(p('smtp://{username}@foo.com/', {username: 'theuser'}), 'to satisfy', { | ||
auth: 'theuser', | ||
username: 'theuser' | ||
}); | ||
}); | ||
it('should populate the password field with an empty string when there is a colon before the @', function () { | ||
expect(p('smtp://{username}:@foo.com/', {username: 'theuser'}), 'to satisfy', { | ||
auth: 'theuser:', | ||
username: 'theuser', | ||
password: '' | ||
}); | ||
}); | ||
describe('Colons in usernames', function () { | ||
var tpl = p('proto://{u}:{p}@domain.tld/foobar/'); | ||
it('Can handle : in username', function () { | ||
var out = tpl({u: 'user:name', p: 'pwd'}); | ||
assert.propertyVal(out, 'auth', 'user:name:pwd'); | ||
assert.propertyVal(out, 'username', 'user:name'); | ||
assert.propertyVal(out, 'password', 'pwd'); | ||
expect(tpl({u: 'user:name', p: 'pwd'}), 'to satisfy', { | ||
auth: 'user:name:pwd', | ||
username: 'user:name', | ||
password: 'pwd' | ||
}); | ||
}); | ||
it('Can handle : in password', function () { | ||
var out = tpl({u: 'u', p: 'pass:word'}); | ||
assert.propertyVal(out, 'auth', 'u:pass:word'); | ||
assert.propertyVal(out, 'username', 'u'); | ||
assert.propertyVal(out, 'password', 'pass:word'); | ||
expect(tpl({u: 'u', p: 'pass:word'}), 'to satisfy', { | ||
auth: 'u:pass:word', | ||
username: 'u', | ||
password: 'pass:word' | ||
}); | ||
}); | ||
it('Can handle : in username & password', function () { | ||
var out = tpl({u: 'user:name', p: 'pass:word'}); | ||
assert.propertyVal(out, 'auth', 'user:name:pass:word'); | ||
assert.propertyVal(out, 'username', 'user:name'); | ||
assert.propertyVal(out, 'password', 'pass:word'); | ||
expect(tpl({u: 'user:name', p: 'pass:word'}), 'to satisfy', { | ||
auth: 'user:name:pass:word', | ||
username: 'user:name', | ||
password: 'pass:word' | ||
}); | ||
}); | ||
@@ -68,7 +86,7 @@ }); | ||
describe('does not touch the non-atomic parts of the parsed url', function () { | ||
var tpl = p('http://foo.com/{?url}'); | ||
it('leaves chars encoded by url-template alone in href', function () { | ||
var out = tpl({url: 'http://bar.com/?quux=baz&blah=blerg'}); | ||
assert.propertyVal(out, 'href', 'http://foo.com/?url=http%3A%2F%2Fbar.com%2F%3Fquux%3Dbaz%26blah%3Dblerg'); | ||
expect(p('http://foo.com/{?url}')({url: 'http://bar.com/?quux=baz&blah=blerg'}), 'to satisfy', { | ||
href: 'http://foo.com/?url=http%3A%2F%2Fbar.com%2F%3Fquux%3Dbaz%26blah%3Dblerg' | ||
}); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
28434
727
1
0