Roundup Tracker - Issues

Issue 927745

classification
urls for attachments are not encoded correctly
Type: Severity: normal
Components: None Versions:
process
Status: closed fixed
:
: : myers_carpenter, richard
Priority: normal :

Created on 2004-04-01 19:14 by myers_carpenter, last changed 2004-04-06 19:48 by myers_carpenter.

Messages
msg1161 Author: [hidden] (myers_carpenter) Date: 2004-04-01 19:14
I have an attachement with the filename

"Pic 3 - 100% zoom.JPG"

The url you get when you click on it is:

http://[...]/issues/file10/Pic%203%20-%20100%%20zoom.JPG

Note the % isn't encoded.
msg1162 Author: [hidden] (richard) Date: 2004-04-02 03:42
Logged In: YES 
user_id=6405

If you view the source of the page containing that 
link, you'll notice that the attribute value is correctly 
quoted. 
 
It looks like your browser is correctly quoting the 
spaces in the URL for its request, but not escaping 
existing %. I'm not sure there's a work-around for 
this, except renaming the file in the database. 
 
To make that easier, add this extra column to your 
file listing (sorry, will wrap badly): 
 
  <td><a tal:condition="file/is_edit_ok" 
          tal:attributes="href 
string:file${file/id}">edit</a></td> 
 
Which browser, BTW? 
msg1163 Author: [hidden] (myers_carpenter) Date: 2004-04-04 01:10
Logged In: YES 
user_id=335935

My browser: Mozilla FireFox or Galeon

Ok so the HTML looks like this:

    <a href="file10/Pic 3 - 100% zoom.JPG">Pic 3 - 100%
zoom.JPG</a>

My browser is converting spaces to %20 to render broken pages.  

The URI spec says spaces aren't allowed: 
http://www.ietf.org/rfc/rfc2396.txt

And the HTML specs says that href attribs are only supposed
to have URI's.  

How do you urlencode a string in TAL?
msg1164 Author: [hidden] (richard) Date: 2004-04-04 08:31
Logged In: YES 
user_id=6405

It works fine for me in firefox and konqueror, hence my question :) 
 
My reading of the spec is that space etc. are to be considered unsafe. I 
guess I'll have to figure how to patch TAL to cope with this special-case 
(and img src, meta link and anything else that has a URI). Bleah. The 
TAL code is hard to understand at the best of times ;) 
 
As for manual encoding of a string, there's currently no mechanism for 
it. When I figure the TAL code out, the encoding will be automatic for the 
appropriate attributes. Brian help us if someone *doesn't* want the 
encoding, as trying to add support for "structure" would probably break 
my brain :) 
 
In the interim, you could add a method to the TemplatingUtils class (see 
the customisation doc). I'll make a note to add the method to the default 
templating utils  
class. 
msg1165 Author: [hidden] (myers_carpenter) Date: 2004-04-06 19:48
Logged In: YES 
user_id=335935

It would seem like the easiest thing to do is get
urllib.urlencode into what ever namespace "python:" draws from

Then it gets fuzzy because I'm don't grok TAL.  Somehow change:

    <a tal:attributes="href string:file${file/id}/${file/name}"
       tal:content="file/name">dld link</a>

To use python:urlencode(${file/name})

I'm remarking this bug as open since you seem to agree it's
a problem.
msg1166 Author: [hidden] (richard) Date: 2004-04-06 22:11
Logged In: YES 
user_id=6405

Oops, sorry, forgot to leave a comment here when I last visited the 
issue. 
 
I've added quoting methods to the "utils" object in the TALES 
namespace. That means: 
 
url_quote       quote some text as safe for a URL (ie. space, %, ...) 
html_quote      quote some text as safe in HTML (ie. <, >, ...) 
 
You use these as "python:utils.url_quote(file.name)". 
 
To get the benefit of these methods without running CVS HEAD, add this 
to your tracker's interfaces.py TemplatingUtils class: 
 
    def url_quote(self, url): 
        '''URL-quote the supplied text.''' 
        import urllib 
        return urllib.quote(url) 
 
    def html_quote(self, html): 
        '''HTML-quote the supplied text.''' 
        import cgi 
        return cgi.escape(url) 
 
msg1167 Author: [hidden] (myers_carpenter) Date: 2004-04-06 23:53
Logged In: YES 
user_id=335935

So how do you write the line:

href string:file${file/id}/${file/name}

with these new python stuff? 
msg1168 Author: [hidden] (richard) Date: 2004-04-07 00:02
Logged In: YES 
user_id=6405

"href python:utils.url_quote('file%s/%s'%(file.id, file.name))" 
 
History
Date User Action Args
2004-04-01 19:14:19myers_carpentercreate