Skip to content

Commit

Permalink
Merge pull request #273 from flatiron/encoded
Browse files Browse the repository at this point in the history
Encoded params
  • Loading branch information
3rd-Eden committed Dec 16, 2014
2 parents 81de1fb + 781ccb6 commit 5f98a7c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,9 +1,9 @@
language: node_js

node_js:
- 0.8
- "0.8"
- "0.10"
- 0.11
- "0.11"

notifications:
email:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,14 @@ etc).
* [API Documentation](#api-documentation)
* [Frequently Asked Questions](#faq)

## Building client-side script

Run the provided CLI script.

```bash
./bin/build
```

## Client-side Routing

It simply watches the hash of the URL to determine what to do, for example:
Expand Down
6 changes: 3 additions & 3 deletions build/director.js
@@ -1,8 +1,8 @@


//
// Generated on Sat Dec 06 2014 16:08:09 GMT-0500 (EST) by Charlie Robbins, Paolo Fragomeni & the Contributors (Using Codesurgeon).
// Version 1.2.4
// Generated on Tue Dec 16 2014 12:13:47 GMT+0100 (CET) by Charlie Robbins, Paolo Fragomeni & the Contributors (Using Codesurgeon).
// Version 1.2.6
//

(function (exports) {
Expand Down Expand Up @@ -341,7 +341,7 @@ function paramifyString(str, params, mod) {
}
}
}
return mod === str ? "([._a-zA-Z0-9-]+)" : mod;
return mod === str ? "([._a-zA-Z0-9-%()]+)" : mod;
}

function regifyString(str, params) {
Expand Down
6 changes: 3 additions & 3 deletions build/director.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/director/http/index.js
Expand Up @@ -124,7 +124,7 @@ Router.prototype.dispatch = function (req, res, callback) {
//
// Trap bad URLs from `decodeUri`
//
try { url = decodeURI(req.url.split('?', 1)[0]) }
try { url = decodeURI(req.url.split('?', 1)[0]); }
catch (ex) { url = null }

if (url && this._hasAccepts) {
Expand Down
2 changes: 1 addition & 1 deletion lib/director/router.js
Expand Up @@ -84,7 +84,7 @@ function paramifyString(str, params, mod) {
}

return mod === str
? '([._a-zA-Z0-9-]+)'
? '([._a-zA-Z0-9-%()]+)'
: mod;
}

Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"name": "director",
"description": "A client Side/Server Side Router",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",
"version": "1.2.5",
"version": "1.2.6",
"maintainers": [
"hij1nx <paolo@nodejitsu.com>",
"beaugunderson <beau@beaugunderson.com>"
Expand All @@ -23,10 +23,10 @@
"devDependencies": {
"api-easy": "0.4.x",
"codesurgeon": "https://github.com/hij1nx/codesurgeon/tarball/master",
"colors": "~1.0.3",
"qunitjs": "~1.9.x",
"request": "~2.49.0",
"uglify-js": "~2.4.15",
"colors": "1.0.x",
"qunitjs": "1.9.x",
"request": "2.49.x",
"uglify-js": "2.4.x",
"vows": "0.7.x"
},
"ender": "./build/ender.js",
Expand Down
2 changes: 1 addition & 1 deletion test/server/core/mount-test.js
Expand Up @@ -71,7 +71,7 @@ vows.describe('director/core/mount').addBatch({
assertRoute(foobar, ['foo', 'jitsu', 'then', 'before'], router.routes);
assertRoute(foobazzbuzz, ['foo', 'bazz', 'buzz', 'on'], router.routes);
assertRoute(foostar, ['foo', 'jitsu', 'then', 'now', 'on'], router.routes);
assertRoute(foodog, ['foo', '([._a-zA-Z0-9-]+)', 'on'], router.routes);
assertRoute(foodog, ['foo', '([._a-zA-Z0-9-%()]+)', 'on'], router.routes);
},

"should accept string path": function(router) {
Expand Down
2 changes: 1 addition & 1 deletion test/server/core/path-test.js
Expand Up @@ -34,7 +34,7 @@ vows.describe('director/core/path').addBatch({

assert.isFunction(router.routes.foo.on);
assert.isObject(router.routes.regions);
assert.isFunction(router.routes.regions['([._a-zA-Z0-9-]+)'].on);
assert.isFunction(router.routes.regions['([._a-zA-Z0-9-%()]+)'].on);
},
"should dispatch the function correctly": function (router) {
router.dispatch('on', '/regions/newyork')
Expand Down
31 changes: 31 additions & 0 deletions test/server/http/http-test.js
Expand Up @@ -38,6 +38,7 @@ vows.describe('director/http').addBatch({
"when passed to an http.Server instance": {
topic: function (router) {
router.get(/foo\/bar\/(\w+)/, handlers.respondWithId);
router.get(/add\/:param\/bark/, handlers.respondWithId);
router.get(/foo\/update\/(\w+)/, handlers.respondWithId);
router.path(/bar\/bazz\//, function () {
this.get(/(\w+)/, handlers.respondWithId);
Expand All @@ -53,6 +54,36 @@ vows.describe('director/http').addBatch({
"a request to bar/bazz/bark": assertBark('bar/bazz/bark'),
"a request to foo/bar/bark?test=test": assertBark('foo/bar/bark?test=test'),
"a request to foo/wild/bark": assertBark('foo/wild/bark'),
"a request to add/:param/bark": {
topic: function () {
request({ uri: 'http://localhost:9090/add/test/bark' }, this.callback);
},
'should respond and parse the params': function (err, res, body) {
assert.isNull(err);
assert.equal(res.statusCode, 200);
assert.equal(body, 'hello from (test)');
}
},
"an encoded request to add/:param/bark": {
topic: function () {
request({ uri: 'http://localhost:9090/add/something%40example.com/bark' }, this.callback);
},
'should respond and parse the params': function (err, res, body) {
assert.isNull(err);
assert.equal(res.statusCode, 200);
assert.equal(body, 'hello from (something%40example.com)');
}
},
"an encoded request to add/:param/bark with additional special characters": {
topic: function () {
request({ uri: 'http://localhost:9090/add/something%40(example).com/bark' }, this.callback);
},
'should respond and parse the params': function (err, res, body) {
assert.isNull(err);
assert.equal(res.statusCode, 200);
assert.equal(body, 'hello from (something%40(example).com)');
}
},
"a request to foo/%RT": macros.assert404(9090, 'foo/%RT'),
"a request to /v2/somepath": macros.assertGet(
9090,
Expand Down

0 comments on commit 5f98a7c

Please sign in to comment.