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

[8.x] Don't pluralise string if string ends with none alphanumeric character #36137

Merged
merged 5 commits into from
Feb 4, 2021

Conversation

crynobone
Copy link
Member

Avoid scenarios such as below.

image

Right now we still enable adding s for string ending with numeric to avoid breaking change for Model to table name naming convention.

Signed-off-by: Mior Muhammad Zaki crynobone@gmail.com

…aracter.

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@GrahamCampbell GrahamCampbell changed the title [8.x] Don't pluralise string if string ends with none alphanumeric character. [8.x] Don't pluralise string if string ends with none alphanumeric character Feb 4, 2021
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@taylorotwell taylorotwell merged commit dfa5420 into laravel:8.x Feb 4, 2021
@bcalik
Copy link

bcalik commented Feb 9, 2021

Can we see how much this preg_match query affects performance?

@@ -69,7 +69,7 @@ class Pluralizer
*/
public static function plural($value, $count = 2)
{
if ((int) abs($count) === 1 || static::uncountable($value)) {
if ((int) abs($count) === 1 || static::uncountable($value) || preg_match('/^(.*)[A-Za-z0-9\x{0080}-\x{FFFF}]$/u', $value) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this thoroughly reviewed?

  • Initial anchor and pattern ^(.*) is superfluous
  • Simpler pattern is /\p{Letter}$/u is more readable
  • The check could be done in uncountable()

@crynobone crynobone deleted the patch-1 branch February 17, 2021 01:04
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.

6 participants