Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Intl] fix Locale::getFallback() throwing exception on long $locale #40162

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

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

AmirHo3ein13
Copy link
Contributor

@AmirHo3ein13 AmirHo3ein13 commented Feb 12, 2021

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #39100
License MIT
Doc PR

Locale::getFallback() throws an exception when the $locale length is greater than INTL_MAX_LOCALE_LEN so I added a condition to check if locale_parse return null, the Locale::getFallback() don't call \count function and just return null instead.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@AmirHo3ein13 AmirHo3ein13 force-pushed the ticket_39100 branch 2 times, most recently from 8f96c7a to a41a1c7 Compare February 12, 2021 11:02
@OskarStark
Copy link
Contributor

Thanks for your contribution, could you please add a testcase to avails a regression in the future?

Also it looks like your commit/email is not associated with your github account 🧐

@OskarStark
Copy link
Contributor

Friendly ping @ro0NL

src/Symfony/Component/Intl/Locale.php Outdated Show resolved Hide resolved
@AmirHo3ein13
Copy link
Contributor Author

Thanks for your contribution, could you please add a testcase to avails a regression in the future?

Also it looks like your commit/email is not associated with your GitHub account

@OskarStark thanks for your review. At first, I added a test case for my change but seems like in CI (appveyor) the \function_exists('locale_parse') returns false and it does not reach my change. As you can see, it is in my first commit, can you help me?

Also thank you for informing me about the email. I'll fix it and commit with the right email.

@AmirHo3ein13
Copy link
Contributor Author

@OskarStark @ro0NL seems like there is a problem with Doctrine, you can see it here. Please check it, thanks in advance.

@xabbuh
Copy link
Member

xabbuh commented Feb 14, 2021

The Doctrine failure isn't related. We can ignore it here.

src/Symfony/Component/Intl/Locale.php Outdated Show resolved Hide resolved
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Can you please add a test case?

@AmirHo3ein13
Copy link
Contributor Author

Can you please add a test case?

@nicolas-grekas as I wrote here, I have a problem testing my change and I need some help. Can you help me?

Thanks for your contribution, could you please add a testcase to avails a regression in the future?
Also it looks like your commit/email is not associated with your GitHub account

@OskarStark thanks for your review. At first, I added a test case for my change but seems like in CI (appveyor) the \function_exists('locale_parse') returns false and it does not reach my change. Can you help me?

@nicolas-grekas
Copy link
Member

Can you add the test to the PR?
The test case should have the @requires function locale_parse annotation on it.

@AmirHo3ein13
Copy link
Contributor Author

Can you add the test to the PR?
The test case should have the @requires function locale_parse annotation on it.

@nicolas-grekas thank you very much. I added the test successfully.

'LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=fr_FR.UTF-8;'.
'LC_ADDRESS=fr_FR.UTF-8;LC_TELEPHONE=fr_FR.UTF-8;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=fr_FR.UTF-8';

$this->assertNull(Locale::getFallback($locale));
Copy link
Contributor

Choose a reason for hiding this comment

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

do we agree root is the fallback then?

compared to above test $this->assertSame('root', Locale::getFallback('nl'));

Copy link
Contributor

Choose a reason for hiding this comment

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

actually $defaultFallback / en is expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ro0NL the function is returning null on long $locale by this change:
$localeSubTags = locale_parse($locale) ?? ['language' => $locale];

Copy link
Member

Choose a reason for hiding this comment

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

I think null is correct also.

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

no strong opinion behavior-wise, null is reasonable

@nicolas-grekas
Copy link
Member

Thank you @AmirHo3ein13.

@nicolas-grekas nicolas-grekas merged commit 9765b5a into symfony:4.4 Feb 17, 2021
This was referenced Mar 4, 2021
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.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.