Opened 10 months ago

Last modified 6 months ago

#35278 assigned Bug

`ngettext` result can be possibly undefined.

Reported by: Piotr Kawula Owned by: Clara
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 (8)

comment:1 by Piotr Kawula, 10 months ago

Description: modified (diff)

comment:2 by Natalia Bidart, 9 months 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, 9 months ago

Tentatively accepting.

comment:4 by Natalia Bidart, 9 months ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:5 by Claude Paroz, 9 months ago

Has patch: set
Patch needs improvement: set

comment:6 by Clara, 6 months ago

Owner: changed from Piotr Kawula to Clara

Getting the ticket to fix the test problem.

comment:7 by Clara, 6 months ago

Patch needs improvement: unset

comment:8 by Clara, 6 months ago

Patch needs improvement: set

We found the tag to execute selenium test --selenium in documentation now, so that was not the issue.

Note: See TracTickets for help on using tickets.
Back to Top