#33603: Backslashes in template tag arguments are escaped
-------------------------------------------+------------------------
               Reporter:  bhch             |          Owner:  nobody
                   Type:  Bug              |         Status:  new
              Component:  Template system  |        Version:  3.2
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 I've written a custom template tag to replace parts of a value:

 {{{
 @register.simple_tag
 def string_replace(value, old, new):
     return value.replace(old, new)
 }}}

 And I'm using it to replace newline characters with commas in a user's
 address:

 {{{
 {% string_replace user.address '\r\n'  ',' %}
 }}}

 However, this doesn't work.

 The reason is that when Django loads a template using Python's
 `file.read()` function, the backslashes get escaped which means `\r\n`
 becomes `\\r\\n`.

 So, the `string_replace` tag actually receives `\\r\\n` instead of `\r\n`.
 This also affects other tags as well.

 Shouldn't Django pass the original string argument to the template tag as
 intended?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33603>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107017fcc216f99-a8aa9ba1-3c1f-46fa-a745-194b650699f2-000000%40eu-central-1.amazonses.com.

Reply via email to