#21316 closed Cleanup/optimization (fixed)
mark_safe documentation should note that strings will become unsafe if modified.
Reported by: | Owned by: | Tim Graham | |
---|---|---|---|
Component: | Documentation | Version: | 1.4 |
Severity: | Normal | Keywords: | mark_safe |
Cc: | vijay_shanker | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
This took me a while to figure out what was happening and it would be good to have this documented somewhere.
In [1]: from django.utils.safestring import mark_safe In [2]: s = "<blink>hello world</blink> " In [3]: type(s) Out[3]: str In [4]: t = mark_safe(s) # t is now 'safe': In [5]: type(t) Out[5]: django.utils.safestring.SafeBytes # let's remove that unnecessary white space.... In [6]: type(t.strip()) Out[6]: str # and we're not safe anymore.
Attachments (1)
Change History (8)
comment:1 by , 11 years ago
Component: | Template system → Documentation |
---|---|
Easy pickings: | set |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 11 years ago
Attachment: | mark_safe_21316.txt added |
---|
added a sentence and a code example to how modified strings are not safe
comment:3 by , 11 years ago
Cc: | added |
---|
comment:4 by , 11 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Triage Stage: | Accepted → Ready for checkin |
I will go ahead and commit this with the following fixes:
- The patch introduces some undesired whitespace in random places. I suggest you set your edit to remove trailing whitespace.
- The patch uses tabs for indentation; it should use spaces instead.
Tips:
- Don't forget to check "Has patch" on the ticket so it shows up for review.
- Use a
diff
orpatch
file extension rather thantxt
so that Trac does syntax highlighting when viewing the patch.
Thank-you for the contribution.
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
If you'd like to provide a patch, I'll be happy to review and commit it.