Opened 2 months ago

Last modified 7 weeks ago

#35278 assigned Bug

`ngettext` result can be possibly undefined.

Reported by: Piotr Kawula Owned by: Piotr Kawula
Component: Internationalization Version: 5.0
Severity: Normal Keywords: ngettext, catalog, i18n, internationalization,
Cc: Piotr Kawula, Claude Paroz Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Piotr Kawula)

When the translation engine provide an invalid plural rule the pluralidx function can return invalid index which will cause the ngettext to return value that does not exist - undefined.
Same result can occur when the newcatalog contains invalid values, for example:

const newcatalog = {
  '%s something': [],
  ...
}

And in ngettext we have:

django.ngettext = function(singular, plural, count) {
 const value = django.catalog[singular];
 if (typeof value === 'undefined') {
    return (count == 1) ? singular : plural;
  } else {
    return value.constructor === Array ? value[django.pluralidx(count)] : value;
  }
};

Which in case of empty array go for value[django.pluralidx(count)] which is undefined.

I think we want the ngettext function to return string always, if it does not find proper value in catalog, should default to the provided values.

It affects the previous versions too.

Change History (5)

comment:1 by Piotr Kawula, 2 months ago

Description: modified (diff)

comment:2 by Natalia Bidart, 8 weeks ago

Cc: Claude Paroz added

Thank you Piotr for your report.

Claude, would you have an opinion about this report? Thank you!

comment:3 by Natalia Bidart, 8 weeks ago

Tentatively accepting.

comment:4 by Natalia Bidart, 8 weeks ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:5 by Claude Paroz, 7 weeks ago

Has patch: set
Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top