Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle dots in resource ids correctly #27

Closed
wants to merge 1 commit into from

2 participants

@Swatinem

Previously a GET /resource/foo.bar.json parsed this into id=foo and format=bar.json
This is fixed now and results in id=foo.bar and format=json

@tj
Owner
tj commented

we should fix this in the express router, ".:format" is special-cased in there so the same tweak should apply

@Swatinem

Fixed in express.

@Swatinem Swatinem closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 26, 2011
  1. @Swatinem
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 2 deletions.
  1. +1 −1  index.js
  2. +24 −1 test/resource.content-negotiation.test.js
View
2  index.js
@@ -116,7 +116,7 @@ Resource.prototype.map = function(method, path, fn){
var route = this.base + (this.name || '');
if (this.name && path) route += '/';
route += path;
- route += '.:format?';
+ route += '.:format([^\/\.]+)?';
// register the route so we may later remove it
(this.routes[method] = this.routes[method] || {})[route] = {
View
25 test/resource.content-negotiation.test.js
@@ -154,5 +154,28 @@ module.exports = {
assert.response(app,
{ url: '/users/1/pets.json' },
{ body: '["tobi","jane","loki"]' });
+ },
+
+ 'test ids with dots': function(){
+ var app = express.createServer();
+ app.resource('tests', {show: {
+ json: function(req, res){
+ res.send(req.params.test);
+ }, default: function(req, res){
+ res.send(406);
+ }}}, { format: 'json' });
+ assert.response(app,
+ { url: '/tests/foo' },
+ { body: 'foo'});
+
+ assert.response(app,
+ { url: '/tests/foo.json' },
+ { body: 'foo' });
+ assert.response(app,
+ { url: '/tests/foo.bar.json' },
+ { body: 'foo.bar' });
+ assert.response(app,
+ { url: '/tests/foo.bar' },
+ { status: 406 });
}
-};
+};
Something went wrong with that request. Please try again.