[Django] #19988: django.contrib.humanize : ordinal returns escaped HTML code in some languages

7 views
Skip to first unread message

Django

unread,
Mar 5, 2013, 7:17:07 AM3/5/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------+-------------------------------------------
Reporter: | Owner: nobody
maxime.lorant@… | Status: new
Type: Bug | Version: 1.5
Component: | Keywords: humanize ordinal html escaped
contrib.humanize | Has patch: 0
Severity: Normal | UI/UX: 0
Triage Stage: Unreviewed |
Easy pickings: 1 |
-------------------------------+-------------------------------------------
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 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.

Django

unread,
Mar 5, 2013, 9:55:29 AM3/5/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner: matiasb
Type: Bug | Status: assigned
Component: contrib.humanize | Version: 1.5
Severity: Normal | Resolution:
Keywords: humanize ordinal | Triage Stage: Accepted
html escaped | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by matiasb):

* 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>

Django

unread,
Mar 11, 2013, 10:26:15 PM3/11/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner: matiasb
Type: Bug | Status: assigned
Component: contrib.humanize | Version: 1.5
Severity: Normal | Resolution:
Keywords: humanize ordinal | Triage Stage: Accepted
html escaped | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0

Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by matiasb):

* 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>

Django

unread,
May 28, 2013, 2:34:45 PM5/28/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner: EvilDMP

Type: Bug | Status: assigned
Component: contrib.humanize | Version: 1.5
Severity: Normal | Resolution:
Keywords: humanize ordinal | Triage Stage: Accepted
html escaped | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by EvilDMP):

* 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>

Django

unread,
Sep 6, 2013, 2:12:00 PM9/6/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner:
Type: Bug | garrypolley
Component: contrib.humanize | Status: assigned
Severity: Normal | Version: 1.5
Keywords: humanize ordinal | Resolution:
html escaped | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by garrypolley):

* 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>

Django

unread,
Sep 6, 2013, 2:36:07 PM9/6/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner:
Type: Bug | garrypolley
Component: contrib.humanize | Status: assigned
Severity: Normal | Version: 1.5
Keywords: humanize ordinal | Resolution:
html escaped | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0

| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by garrypolley):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:5>

Django

unread,
Sep 7, 2013, 4:37:46 AM9/7/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner:
Type: Bug | garrypolley
Component: contrib.humanize | Status: assigned
Severity: Normal | Version: 1.5
Keywords: humanize ordinal | Resolution:
html escaped | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* 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>

Django

unread,
Sep 7, 2013, 11:15:06 AM9/7/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner:
Type: Bug | garrypolley
Component: contrib.humanize | Status: assigned
Severity: Normal | Version: 1.5
Keywords: humanize ordinal | Resolution:
html escaped | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by garrypolley):

* cc: garrypolley (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/19988#comment:7>

Django

unread,
Sep 7, 2013, 2:14:02 PM9/7/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner:
Type: Bug | garrypolley
Component: contrib.humanize | Status: closed
Severity: Normal | Version: 1.5
Keywords: humanize ordinal | Resolution: fixed

html escaped | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Garry Polley <garrympolley@…>):

* 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>

Django

unread,
Sep 7, 2013, 2:14:02 PM9/7/13
to django-...@googlegroups.com
#19988: django.contrib.humanize : ordinal returns escaped HTML code in some
languages
-------------------------------------+-------------------------------------
Reporter: maxime.lorant@… | Owner:
Type: Bug | garrypolley
Component: contrib.humanize | Status: closed
Severity: Normal | Version: 1.5
Keywords: humanize ordinal | Resolution: fixed
html escaped | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages