Opened 8 months ago

Last modified 5 months ago

#35278 assigned Bug

`ngettext` result can be possibly undefined. — at Initial Version

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

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.

Change History (0)

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