url-assembler
Advanced tools
Comparing version 1.2.8 to 1.2.9
@@ -56,3 +56,3 @@ var extend = require('extend'); | ||
var chainable = this._chain(); | ||
chainable.pathname = this._prefix + fragment; | ||
chainable.pathname = this._prefix + encodeURI(fragment); | ||
return chainable; | ||
@@ -63,3 +63,3 @@ }; | ||
var chainable = this._chain(); | ||
chainable.pathname = this.pathname + segment; | ||
chainable.pathname = this.pathname + encodeURI(segment); | ||
return chainable; | ||
@@ -83,3 +83,3 @@ }; | ||
var pathToKeep = this.pathname.substr(this._prefix.length); | ||
chainable._prefix = this._prefix + prefix; | ||
chainable._prefix = this._prefix + encodeURI(prefix); | ||
chainable.pathname = chainable._prefix + pathToKeep; | ||
@@ -96,3 +96,3 @@ return chainable; | ||
var symbol = ':' + key; | ||
chainable.pathname = this.pathname.replace(symbol, value); | ||
chainable.pathname = this.pathname.replace(symbol, encodeURI(value)); | ||
if (!strict && chainable.pathname === previous) { | ||
@@ -99,0 +99,0 @@ return chainable.query(key, value); |
{ | ||
"name": "url-assembler", | ||
"version": "1.2.8", | ||
"version": "1.2.9", | ||
"description": "Assemble urls from route-like templates (/path/:param)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var expect = require('chai').expect | ||
var UrlAssembler = require('../') | ||
var Url = require('url') | ||
@@ -67,2 +68,45 @@ describe('an instance with a baseUrl', function () { | ||
describe('when used with special characters', function() { | ||
it('should encode them in the final URL (with template)', function() { | ||
var expected = 'http://www.canal.com:8989' | ||
+ '/pl%C3%BBs' | ||
+ '/CARA%C3%8FBES/m%C3%A9dia/Bouquet%20p%C3%A8re' | ||
+ '?now=2014-05-27T03%3A59%3A59%2B00%3A00&f%C3%B6%C3%B6=b%20a%20r' | ||
myUrl = UrlAssembler('http://www.canal.com:8989') | ||
.prefix('/plûs') | ||
.template('/:zone/média/:media') | ||
.param({'media': 'Bouquet père', 'zone': 'CARAÏBES'}) | ||
.query({now: '2014-05-27T03:59:59+00:00', föö: "b a r"}); | ||
expect(myUrl.toString()).to.equal(expected); | ||
expect(Url.format(myUrl)).to.equal(expected) | ||
}); | ||
it('should encode them in the final URL (with segment)', function() { | ||
var expected = 'http://www.canal.com:8989' | ||
+ '/pl%C3%BBs' | ||
+ '/CARA%C3%8FBES/m%C3%A9dia/Bouquet%20p%C3%A8re' | ||
+ '?now=2014-05-27T03%3A59%3A59%2B00%3A00&f%C3%B6%C3%B6=b%20a%20r' | ||
myUrl = UrlAssembler('http://www.canal.com:8989') | ||
.prefix('/plûs') | ||
.segment('/:zone/média/:media') | ||
.param({'media': 'Bouquet père', 'zone': 'CARAÏBES'}) | ||
.query({now: '2014-05-27T03:59:59+00:00', föö: "b a r"}); | ||
expect(myUrl.toString()).to.equal(expected); | ||
expect(Url.format(myUrl)).to.equal(expected) | ||
}); | ||
it('should encode them in the final URL (with param)', function() { | ||
var expected = 'http://example.com' | ||
+ "/search/-_.!~*'()%20/;,%3F:@&=+$_abc_%E6%97%A5%E6%9C%AC%E8%AA%9E" | ||
myUrl = UrlAssembler('http://example.com') | ||
.segment('/search/:p') | ||
.param({ | ||
'p': "-_.!~*'() /;,?:@&=+$_abc_日本語" | ||
}); | ||
expect(myUrl.toString()).to.equal(expected); | ||
expect(Url.format(myUrl)).to.equal(expected) | ||
}); | ||
}); | ||
}); |
473
24879
13