All, I recently upgraded to Rails 0.13.1 (under Windows XP, running webrick ) and I am experiencing a problem. I have a series of files in a directory called $RAILS/public/files. I can normally get at the file (called file.txt) by pointing my browser to http://localhost:3000/files/file.txt. If the file has a plus sign (''+'') in the name (e.g. fil+e.txt), I get the following error pasted below. Any thoughts on what''s going on here? I tried using the HTML code for ''+'' to no avail. -cal ActionController::RoutingError (Recognition failed for "/files/fil+e.txt"): C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/ \ routing.rb:444:in `recognition_failed'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/ \ routing.rb:434:in `recognize!'' C:/ruby/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/dispatcher.rb:32:in \ `dispatch'' C:/ruby/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/webrick_server.rb:105: \ in `handle_dispatch'' C:/ruby/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/webrick_server.rb:71: \ in `service'' C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' C:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread'' C:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' C:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each'' C:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'' C:/ruby/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/webrick_server.rb:57: \ in `dispatch'' $RAILS/app/script/server:49
Matthew Denner
2005-Aug-15 15:01 UTC
Re: Routing recognition problem: filenames containing ''+''
cal wrote:> I recently upgraded to Rails 0.13.1 (under Windows XP, running webrick ) and I > am experiencing a problem. I have a series of files in a directory called > $RAILS/public/files. I can normally get at the file (called file.txt) by > pointing my browser to http://localhost:3000/files/file.txt. If the file has a > plus sign (''+'') in the name (e.g. fil+e.txt), I get the following error pasted > below. Any thoughts on what''s going on here? I tried using the HTML code for > ''+'' to no avail.The HTML code? Do you mean the HTTP escaped version of ''+'' which is, I think, ''%2b''? So, ''fil%2be.txt''.
Matthew Denner <matt@...> writes:> > cal wrote: > > I recently upgraded to Rails 0.13.1 (under Windows XP, running webrick )and I> > am experiencing a problem. I have a series of files in a directory called > > $RAILS/public/files. I can normally get at the file (called file.txt) by > > pointing my browser to http://localhost:3000/files/file.txt. If the filehas a> > plus sign (''+'') in the name (e.g. fil+e.txt), I get the following errorpasted> > below. Any thoughts on what''s going on here? I tried using the HTML codefor> > ''+'' to no avail. > > The HTML code? Do you mean the HTTP escaped version of ''+'' which is, I > think, ''%2b''? So, ''fil%2be.txt''. >Yes. I tried, as you indicate, ''fil%2be.txt''. I received the same routing recognition message. Perhaps there''s a way in my $RAILS/config/routes.rb to let requests for files in $RAILS/public/files to get passed as-is? -cal
A followup: I added an entry to my $RAILS/config/route.rb file which looks like this: map.connect ''/files/:file'', :controller => ''file'', :action => ''get'' I also added the appropriate controller and action, which simply performs a render_text(@params). Interestingly, the plus sign has been removed from the parameter list. This is the output: When the URL is http://localhost:3000/files/test.txt, I see this: {"action"=>"get", "controller"=>"file", "file"=>"test.txt"} When the URL is http://localhost:3000/files/tes+t.txt, I see this: {"action"=>"get", "controller"=>"file", "file"=>"tes t.txt"} When I use the HTTP escaped character like this: http://localhost:3000/files/tes%2Bt.txt I get this promising result: {"action"=>"get", "controller"=>"file", "file"=>"tes+t.txt"} But removal of the line from routes.rb results in the same recognition error. Any ideas from the RoR-ers out there? -cal
Lord Khaos
2005-Aug-15 18:45 UTC
Re: Re: Routing recognition problem: filenames containing ''+''
> When the URL is http://localhost:3000/files/test.txt, I see this: > {"action"=>"get", "controller"=>"file", "file"=>"test.txt"} > > When the URL is http://localhost:3000/files/tes+t.txt, I see this: > {"action"=>"get", "controller"=>"file", "file"=>"tes t.txt"} > > When I use the HTTP escaped character like this: > http://localhost:3000/files/tes%2Bt.txt > > I get this promising result: > {"action"=>"get", "controller"=>"file", "file"=>"tes+t.txt"} > > But removal of the line from routes.rb results in the same recognition error. > > Any ideas from the RoR-ers out there? > > -calCal, these are just semi-educated guesses, but here''s some things to ponder-- -- As you may know, in an http GET querystring the "+" is the <space> character (eg-- /show?1234+Main+Street) -- mod_rewrite (used with fcgi) makes extensive use of regular expressions, for which the "+" sign also has meaning (match one or more times). Between these two points, I''d say your ''best'' bet is to stear clear of the "+" symbol in file names that are to be resources requested via a URL, but you''ve probably already considered that and have good reason for naming your files as such? That being the case, I _suspect_ (remember that semi-educated disclaimer above?) that the solution is to escape the + sign in the RegEx for your route. But then, I stink at writing regular expressions :) HTH, Howard
Nicholas Seckar
2005-Aug-15 20:00 UTC
Re: Routing recognition problem: filenames containing ''+''
The issue you are seeing is due to the differences in handling the + character. AFAIK, the standard defines that ''+'' => '' '' only in the query part of the URL. However, Routing will produce strings with ''+'' inside the path part of the URL. According to standards, this is incorrect. However, most webservers support(ed?) this usage. Recently however, lighttpd changed to the standard use of +. Due to this change, building links to files inside public/ can be somewhat difficult. It is necessary for you to find out if your webserver will escape a ''+'' to a '' '' when it looks for a file. A while ago, I noticed that webrick did not behave as lighttpd did, so I patched webrick. Since then lighttpd changed their policy... :S I have not yet reverted the patch to webrick, and in reality I would like to see a way to have lighttpd behave as it did before. HTH