Permalink
Browse files

Merge pull request #273 from flatiron/encoded

Encoded params
  • Loading branch information...
3rd-Eden committed Dec 16, 2014
2 parents 81de1fb + 781ccb6 commit 5f98a7c0bf8a86eea2eb176dc70c81fa70360044
@@ -1,9 +1,9 @@
language: node_js

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

notifications:
email:
@@ -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:
@@ -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) {
@@ -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) {

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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) {
@@ -84,7 +84,7 @@ function paramifyString(str, params, mod) {
}

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

@@ -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>"
@@ -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",
@@ -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) {
@@ -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')
@@ -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);
@@ -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,

0 comments on commit 5f98a7c

Please sign in to comment.