Skip to content
This repository

Handle dots in resource ids correctly #27

Closed
wants to merge 1 commit into from

2 participants

Arpad Borsos TJ Holowaychuk
Arpad Borsos

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 Holowaychuk
Owner

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

Arpad Borsos

Fixed in express.

Arpad Borsos Swatinem closed this September 27, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 26, 2011
Arpad Borsos fix content negotiation when the id includes dots f3355fa
This page is out of date. Refresh to see the latest.
2  index.js
@@ -116,7 +116,7 @@ Resource.prototype.map = function(method, path, fn){
116 116
   var route = this.base + (this.name || '');
117 117
   if (this.name && path) route += '/';
118 118
   route += path;
119  
-  route += '.:format?';
  119
+  route += '.:format([^\/\.]+)?';
120 120
 
121 121
   // register the route so we may later remove it
122 122
   (this.routes[method] = this.routes[method] || {})[route] = {
25  test/resource.content-negotiation.test.js
@@ -154,5 +154,28 @@ module.exports = {
154 154
     assert.response(app,
155 155
       { url: '/users/1/pets.json' },
156 156
       { body: '["tobi","jane","loki"]' });
  157
+  },
  158
+  
  159
+  'test ids with dots': function(){
  160
+    var app = express.createServer();
  161
+    app.resource('tests', {show: {
  162
+      json: function(req, res){
  163
+        res.send(req.params.test);
  164
+      }, default: function(req, res){
  165
+        res.send(406);
  166
+      }}}, { format: 'json' });
  167
+    assert.response(app,
  168
+      { url: '/tests/foo' },
  169
+      { body: 'foo'});
  170
+
  171
+    assert.response(app,
  172
+      { url: '/tests/foo.json' },
  173
+      { body: 'foo' });
  174
+    assert.response(app,
  175
+      { url: '/tests/foo.bar.json' },
  176
+      { body: 'foo.bar' });
  177
+    assert.response(app,
  178
+      { url: '/tests/foo.bar' },
  179
+      { status: 406 });
157 180
   }
158  
-};
  181
+};
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.