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 1^er^
{{ 2|ordinal }} becomes 2^e^
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 2^e^ (!!!)
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/19988>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* needs_better_patch: => 0
* needs_tests: => 0
* owner: nobody => matiasb
* needs_docs: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:1>
* has_patch: 0 => 1
Comment:
Proposed pull request: https://github.com/django/django/pull/896
Tests passing for sqlite.
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:2>
* owner: matiasb => EvilDMP
Comment:
I have marked this ticket as suitable for a first-time committer attending
a [https://dont-be-afraid-to-commit.readthedocs.org/ Don't be afraid to
commit workshop].
The next planned session will be hosted by
[http://www.cardiffdevworkshop.com 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:3>
* owner: EvilDMP => garrypolley
Comment:
Submitted a pull request for this issue.
https://github.com/django/django/pull/1565
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:5>
* stage: Ready for checkin => Accepted
Comment:
Please do not mark your own patch as RFC. Someone else should review it.
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:6>
* cc: garrypolley (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"337bd248a5ac13957b3287ec8bd7a8a4e21be53e"]:
{{{
#!CommitTicketReference repository=""
revision="337bd248a5ac13957b3287ec8bd7a8a4e21be53e"
fixes #19988, allow html in ordinal for humanize
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:8>
Comment (by Alex Gaynor <alex.gaynor@…>):
In [changeset:"907f19eba743de3f0720bc2e2cd2fad45b2c0170"]:
{{{
#!CommitTicketReference repository=""
revision="907f19eba743de3f0720bc2e2cd2fad45b2c0170"
Merge pull request #1565 from garrypolley/#19988-ordinal-html-i18n-fix
fixes #19988, allow html in ordinal for humanize
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:9>