Skip to content
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

fix plural forms validation #157

Merged
merged 3 commits into from
Dec 19, 2017
Merged

fix plural forms validation #157

merged 3 commits into from
Dec 19, 2017

Conversation

soukicz
Copy link
Contributor

@soukicz soukicz commented Aug 25, 2017

My previous PR #156 missed some characters in plural forms validation

@oscarotero
Copy link
Member

Maybe an easier solution is just check whether the plural form has any letter different than n?
Somethin like this (not tested):

if (preg_match('/[A-Ma-mO-Zo-z]/', str_replace('return ', '', $code)) {
    throw new \InvalidArgumentException('Invalid Plural form: ' . $code);
}

Just an idea, what do you think?

@soukicz
Copy link
Contributor Author

soukicz commented Aug 25, 2017

It would be also better to check it in setter before variable substitution. I will updated it.

@oscarotero
Copy link
Member

We can also test the regexp with all possible formulas to be sure that doesn't fail with any valid plural formula.

$languages = Gettext\Languages\Language::getAll();

foreach ($languages as $language) {
    //test $language->formula
}

@soukicz
Copy link
Contributor Author

soukicz commented Dec 19, 2017

I have simplified validation and added testing for predefined plural forms.

@oscarotero oscarotero merged commit f4cf543 into php-gettext:master Dec 19, 2017
@oscarotero
Copy link
Member

Great. Thank you 👍

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

Successfully merging this pull request may close these issues.

2 participants