#21529 closed Cleanup/optimization (fixed)
url tag urlencodes arguments irreversibly
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.6 |
Severity: | Normal | Keywords: | url tag urlencode javascript js |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | How to create a pull request | ||
Description ¶
Somewhere between 1.4 and 1.6 the url tag started urlencoding arguments before outputing the URL. This breaks code that wants to build the url inside javascript in the following way:
<script> var url = '{% url "some_view" "'+some_js_argument+'" %}' </script>
On 1.4 this generates '/some/view/'+some_js_argument+'/'
On 1.6 this generates '/some/view/%27%2Bsome_js_argument%2B%27'
While I understand the rationale behind urlencoding per default, it would be nice to provide a way to avoid it. "|safe" seems to have no effect and even a custom filter to urldecode the output doesn't help, since urlencoding seems to be the last step before output.
Please consider providing a way to disable this, either by filter or by options to the url tag, so that we're not forced to use kludgy workarounds like
<script> var url = '{% url "some_view" "ARGUMENT_BY_JS" %}'.replace(/ARGUMENT_BY_JS/, some_js_argument) </script>
Additionally, this might be a good thing to mention in the docs.
This is admittedly somewhere between a bug and a feature request, but since this breaks old code, I've decided to submit it as a regression bug.
Change History (6)
comment:1 by , 11 years ago
Component: | Template system → Documentation |
---|---|
Needs documentation: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
by , 11 years ago
Attachment: | 21529.diff added |
---|
comment:2 by , 11 years ago
Has patch: | set |
---|---|
Needs documentation: | unset |
comment:4 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I think the url tag should always return proper URLs, but we should document it clearly.