Skip to content

gh-56634: Gettext: raise descriptive error on empty plural-forms value #112895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

m-aciek
Copy link
Contributor

@m-aciek m-aciek commented Dec 9, 2023

Raising ValueError with descriptive error message. It handles empty Plural-Forms like "Plural-Forms: \n" (original downstream bug, and fix) but also lack of plural= keyword, like "Plural-Forms: nplurals=4;\n". In the #56634 ignoring the incorrect syntax was being discussed, as well as issuing warnings. The implementation here is following the suggestion of @serhiy-storchaka of raising an error instead.

@m-aciek m-aciek force-pushed the gettext-handle-incorrect-plural-forms branch from a2515c9 to 17baf50 Compare December 9, 2023 11:33
@m-aciek m-aciek changed the title gh-56634: Gettext: handle gracefully empty plural-forms value gh-56634: Gettext: raise descriptive error on empty plural-forms value Dec 9, 2023
@m-aciek m-aciek force-pushed the gettext-handle-incorrect-plural-forms branch from 17baf50 to e38c34c Compare December 9, 2023 11:35
@m-aciek m-aciek force-pushed the gettext-handle-incorrect-plural-forms branch from e38c34c to e148f83 Compare December 9, 2023 11:37
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add similar change for content-type?

try:
plural = v[1].split('plural=')[1]
except IndexError as e:
raise ValueError('invalid plural forms syntax') from e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from e is not needed, that index error does not add useful information. It is just an implementation detail (we could use the length checks instead, or regular expressions). Use from None instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants