Code

Opened 8 years ago

Closed 7 years ago

#2694 closed enhancement (invalid)

[patch] urlencode to use optional safe argument for urllib.quote

Reported by: Kaaya Owned by: nobody
Component: Core (Other) Version:
Severity: trivial Keywords: urlencode
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I know this issue got set as wontfix before but the previous solution was not backwards compatible and this one is.

def urlencode(value, safe='/'):
    "Escapes a value for use in a URL"
    import urllib
    return urllib.quote(value, safe)

urlencode will work exactly as is does now but can *optionally* set which characters won't be escaped. The / character is the default for urllib.quote http://docs.python.org/lib/module-urllib.html

Test case for this is when you have a url stored in the db e.g. "http://djangoproject.com/" if you do a var|urlencode on that you get back 'http%3Adjangoproject.com/' which will cause the browser to show http://example.com/http://djangoproject.com/ which is not what you want but if you can use var|urlencode:":/" you'll get the link working properly.

Attachments (0)

Change History (2)

comment:1 Changed 7 years ago by Simon G. <dev@…>

  • Has patch set
  • Keywords urlencode added
  • Summary changed from urlencode to use optional safe argument for urllib.quote to [patch] urlencode to use optional safe argument for urllib.quote
  • Triage Stage changed from Unreviewed to Design decision needed

I like the fact that this doesn't break the backwards compatibility, and does add some functionality in an easy way. However, I'm not sure how much of a problem this to warrent a check in?

comment:2 Changed 7 years ago by jacob

  • Resolution set to invalid
  • Status changed from new to closed

I don't really understand the use case for this. urlencoding the ":" in URIs is correct for your example.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.