4 messages in com.googlegroups.pylons-discussRe: Routes generates bad URLs with ar...
FromSent OnAttachments
Mike Orr16 Mar 2007 16:11 
Damjan16 Mar 2007 21:39 
Mike Orr16 Mar 2007 22:07 
Ian Bicking17 Mar 2007 08:25 
Subject:Re: Routes generates bad URLs with args containing spaces
From:Mike Orr (slug@public.gmane.org)
Date:03/16/2007 10:07:42 PM
List:com.googlegroups.pylons-discuss

Maybe, but something's not finding the files if the URL has a + in it.

--Mike

On 3/16/07, Damjan <gdam@public.gmane.org> wrote:

Isn't + and %20 considered the same in HTTP??

On Mar 17, 12:12 am, "Mike Orr"
<slug@public.gmane.org> wrote:

I have a bunch of images with spaces in the filenames. I need to embed the filename in the URL with the proper escaping, so: 6001/1355/SHELLNAIRN08OCT05 _24_.jpg should be: /attachments/6001/1355/SHELLNAIRN08OCT05%20_24_.jpg

I have a route like this:

NUMERIC = R"\d+" map.connect("attachment", "/attachments/:orr_id/:entry_id/:filename", requirements={"orr_id": NUMERIC, "entry_id": NUMERIC})

$ paster shell development.ini>>> h.url_for("attachment", orr_id=6001,
entry_id=1355,

filename='SHELLNAIRN08OCT05 _24_.jpg') '/attachments/6001/1355/SHELLNAIRN08OCT05+_24_.jpg'

Oops, it quoted it query-string style. Maybe I should escape the argument myself.

h.url_for("attachment", orr_id=6001, entry_id=1355,

filename='SHELLNAIRN08OCT05%20_24_.jpg') '/attachments/6001/1355/SHELLNAIRN08OCT05%2520_24_.jpg'

Now it double-quoted. Is this a bug or am I using it wrong? My Quixote application uses "%20" for spaces and has never had a problem finding the images.

My current workaround is to replace the '+' afterward.

url = h.url_for("attachment", orr_id=6001, entry_id=1355,

filename='SHELLNAIRN08OCT05 _24_.jpg')>>> url.replace("+", "%20")

'/attachments/6001/1355/SHELLNAIRN08OCT05%20_24_.jpg'