#19988 closed Bug (fixed)
django.contrib.humanize : ordinal returns escaped HTML code in some languages
Reported by: | Owned by: | Garry Polley | |
---|---|---|---|
Component: | contrib.humanize | Version: | 1.5 |
Severity: | Normal | Keywords: | humanize ordinal html escaped |
Cc: | Garry Polley | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Hi guys,
I found that the ordinal filter returns escaped HTML in some languages, due to the translation. In English, the filter make this:
{{ 1|ordinal }} becomes 1st
{{ 2|ordinal }} becomes 2nd
In French, the expected behavior is:
{{ 1|ordinal }} becomes 1er
{{ 2|ordinal }} becomes 2e
However, with Django 1.4 and 1.5 (haven't try with older versions but do we really care now ?), I got:
{{ 1|ordinal }} becomes 1<sup>er</sup>
{{ 2|ordinal }} becomes 2<sup>e</sup>
{{ "2"|ordinal }} becomes 2e (!!!)
As you can see, the HTML is escaped if the argument is a int, and it doesn't if the argument is a string, precisely à SafeString in the filter. I've tried to patch this bug by marking the output string safe, cast the argument in the filter, etc. No success. I think it's possible with a single line, but I hope someone more competent will found this in one second :)
The problem comes from the translation, which can returns HTML in some languages. You can try with LANGUAGE_CODE = 'fr-fr' to test it.
Change History (9)
comment:1 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 12 years ago
Has patch: | set |
---|
comment:3 by , 12 years ago
Owner: | changed from | to
---|
I have marked this ticket as suitable for a first-time committer attending a Don't be afraid to commit workshop.
The next planned session will be hosted by Cardiff Dev Workshop on Saturday 8th June.
If you want to tackle this ticket before then, or at any time in fact, please don't let the fact that it's assigned to me stop you. Feel free to re-assign it to yourself and do whatever you like to it.
comment:5 by , 11 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 11 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
Please do not mark your own patch as RFC. Someone else should review it.
comment:7 by , 11 years ago
Cc: | added |
---|
comment:8 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Proposed pull request: https://github.com/django/django/pull/896
Tests passing for sqlite.