[Django] #29853: Exported jsi18n ngettext() function doesn't check existence of plural translation before attempting to access it

40 views
Skip to first unread message

Django

unread,
Oct 15, 2018, 8:56:06 PM10/15/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
------------------------------------------------+------------------------
Reporter: itsmemohamed | Owner: nobody
Type: Uncategorized | Status: new
Component: Internationalization | Version: 2.1
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 |
------------------------------------------------+------------------------
In https://docs.djangoproject.com/en/2.0/_modules/django/views/i18n/ the
following exported javascript function
{{{
django.ngettext = function(singular, plural, count) {
var value = django.catalog[singular];
if (typeof(value) == 'undefined') {
return (count == 1) ? singular : plural;
} else {
return value[django.pluralidx(count)];
}
};
}}}
doesn't check the existence of {{{value[1]}}} or {{{value[2]}}} before
attempting to access them if {{{value}}} itself is defined. Therefore will
return undefined if user attempts to access plural translation, when none
is defined.

- If user provides no translations at all for singular or plural strings
it will return formatted un-translated string (Works as expected)
- If user provides translations for singular and plural strings it will
return formatted translated string (Works as expected)
- If user provides singular translation BUT no plural translation it will
return undefined (Unexpected and extremely difficult to debug)

This function should rather fallback to singular translation OR use un-
translated plural string in cases where a singular translation is provided
but no plural translation is provided.

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

Django

unread,
Oct 15, 2018, 8:56:30 PM10/15/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------

Reporter: itsmemohamed | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by itsmemohamed):

* easy: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29853#comment:1>

Django

unread,
Oct 15, 2018, 9:36:12 PM10/15/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------

Reporter: itsmemohamed | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by itsmemohamed:

Old description:

> In https://docs.djangoproject.com/en/2.0/_modules/django/views/i18n/ the
> following exported javascript function
> {{{
> django.ngettext = function(singular, plural, count) {
> var value = django.catalog[singular];
> if (typeof(value) == 'undefined') {
> return (count == 1) ? singular : plural;
> } else {
> return value[django.pluralidx(count)];
> }
> };
> }}}
> doesn't check the existence of {{{value[1]}}} or {{{value[2]}}} before
> attempting to access them if {{{value}}} itself is defined. Therefore
> will return undefined if user attempts to access plural translation, when
> none is defined.
>
> - If user provides no translations at all for singular or plural strings
> it will return formatted un-translated string (Works as expected)
> - If user provides translations for singular and plural strings it will
> return formatted translated string (Works as expected)
> - If user provides singular translation BUT no plural translation it will
> return undefined (Unexpected and extremely difficult to debug)
>
> This function should rather fallback to singular translation OR use un-
> translated plural string in cases where a singular translation is
> provided but no plural translation is provided.

New description:

In https://docs.djangoproject.com/en/2.0/_modules/django/views/i18n/ the
following exported javascript function
{{{
django.ngettext = function(singular, plural, count) {
var value = django.catalog[singular];
if (typeof(value) == 'undefined') {
return (count == 1) ? singular : plural;
} else {
return value[django.pluralidx(count)];
}
};
}}}
doesn't check the existence of {{{value[1]}}} or {{{value[2]}}} before
attempting to access them if {{{value}}} itself is defined. Therefore will
return undefined if user attempts to access plural translation, when none
is defined.

- If user provides no translations at all for singular or plural strings

it will return formatted **un-translated** string (Works as expected)


- If user provides translations for singular and plural strings it will

return formatted **translated** string (Works as expected)


- If user provides singular translation BUT no plural translation it will

return **undefined** (Unexpected and extremely difficult to debug)

This function should rather fallback to singular translation OR use un-
translated plural string in cases where a singular translation is provided
but no plural translation is provided.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29853#comment:2>

Django

unread,
Oct 15, 2018, 10:47:49 PM10/15/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------

Reporter: itsmemohamed | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

Do you think it could be related to #29825,
https://github.com/django/django/pull/10506

--
Ticket URL: <https://code.djangoproject.com/ticket/29853#comment:3>

Django

unread,
Oct 16, 2018, 11:53:05 AM10/16/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------

Reporter: itsmemohamed | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by itsmemohamed):

Replying to [comment:3 Simon Charette]:


> Do you think it could be related to #29825,
https://github.com/django/django/pull/10506

Yeah, they both concern the same function but that's a different failure
mode.

--
Ticket URL: <https://code.djangoproject.com/ticket/29853#comment:4>

Django

unread,
Oct 16, 2018, 7:28:32 PM10/16/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------
Reporter: Mohamed Moustafa | Owner: Serhiy
| Martynenko
Type: Uncategorized | Status: assigned

Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Serhiy Martynenko):

* owner: nobody => Serhiy Martynenko
* status: new => assigned


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

Django

unread,
Oct 16, 2018, 7:38:30 PM10/16/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------
Reporter: Mohamed Moustafa | Owner: Serhiy
| Martynenko
Type: Bug | Status: assigned

Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Serhiy Martynenko):

* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/29853#comment:6>

Django

unread,
Oct 18, 2018, 12:01:59 AM10/18/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------
Reporter: Mohamed Moustafa | Owner: Serhiy
| Martynenko
Type: Bug | Status: assigned
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Serhiy Martynenko):

Do you have example of part of translation file? I tried to reproduce bug
and it looks like JS array with translations as plural has empty string
instead of undefined.

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

Django

unread,
Oct 18, 2018, 10:49:21 AM10/18/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------
Reporter: Mohamed Moustafa | Owner: Serhiy
| Martynenko
Type: Bug | Status: assigned
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Ramiro Morales):

A question we need to ask the reported is how a translation literal which
is malformed i.e. with quantity of plural forms not obeying what the
locale's plural forms formula has reached the translation catalog in the
first place.

AFAIC the compilemessages/msgfmt stage should have rejected the literal
when trying to convert the .po file to .mo.

--
Ticket URL: <https://code.djangoproject.com/ticket/29853#comment:8>

Django

unread,
Oct 24, 2018, 2:46:04 PM10/24/18
to django-...@googlegroups.com
#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------
Reporter: Mohamed Moustafa | Owner: Serhiy
| Martynenko
Type: Bug | Status: closed
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramiro Morales):

* status: assigned => closed
* resolution: => needsinfo


Comment:

I'm closing this for now setting the 'We need more information' flag.

Please reopen if you can answer question in comment:8

--
Ticket URL: <https://code.djangoproject.com/ticket/29853#comment:9>

Reply all
Reply to author
Forward
0 new messages