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

[Validator] Check the BIC country with symfony/intl #28473

Merged
merged 1 commit into from Sep 20, 2018

Conversation

sylfabre
Copy link
Contributor

@sylfabre sylfabre commented Sep 15, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #28167
License MIT
Doc PR N/A

Check the BIC country code against the list from Intl component instead of a simple check alphabetical test.

This PR uses the Intl component which is not part of the required dependencies of the Validator component (https://github.com/symfony/validator/blob/master/composer.json): symfony/intl is only required for dev. So I'm making a PR against master because it may break existing code.
But CountryValidator does the same so it may not be an issue after all.

@sylfabre sylfabre changed the base branch from master to 4.1 September 15, 2018 09:34
@sylfabre sylfabre changed the base branch from 4.1 to master September 15, 2018 09:35
@@ -63,7 +64,8 @@ public function validate($value, Constraint $constraint)
}

// next 2 letters must be alphabetic (country code)
if (!ctype_alpha(substr($canonicalize, 4, 2))) {
$countries = Intl::getRegionBundle()->getCountryNames();
Copy link
Member

Choose a reason for hiding this comment

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

symfony/intl is not an hard dependency for the validator, we need to check if it is installed before using it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chalasr should it be checked for CountryValidator too?

Or should we check against IbanValidator::$formats making it public?

Copy link
Member

Choose a reason for hiding this comment

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

#28513 does it for other validators, let's do the same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chalasr right

@chalasr chalasr added this to the 2.8 milestone Sep 15, 2018
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 19, 2018

Could you please enhance your commit+PR title? This is a requirement for us to generate proper changelogs. Thanks for your help keeping high quality standards.

@sylfabre sylfabre force-pushed the issue_28167 branch 2 times, most recently from c5b174d to 207ace5 Compare September 19, 2018 15:27
@sylfabre sylfabre changed the title Fix #28167 [Validator] Check the BIC country with symfony/intl Fix #28167 Sep 19, 2018
@@ -63,7 +70,11 @@ public function validate($value, Constraint $constraint)
}

// next 2 letters must be alphabetic (country code)
if (!ctype_alpha(substr($canonicalize, 4, 2))) {
if (!class_exists(Intl::class)) {
throw new RuntimeException('The "symfony/intl" component is required to use the Bic constraint.');
Copy link
Member

Choose a reason for hiding this comment

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

should be a LogicException as it involves to fix your code by adding the missing dependency (discussion currently happening in #28513)

@nicolas-grekas nicolas-grekas changed the title [Validator] Check the BIC country with symfony/intl Fix #28167 [Validator] Check the BIC country with symfony/intl Sep 20, 2018
@nicolas-grekas
Copy link
Member

Thank you @sylfabre.

@nicolas-grekas nicolas-grekas merged commit 27bd3a8 into symfony:master Sep 20, 2018
nicolas-grekas added a commit that referenced this pull request Sep 20, 2018
…ylfabre)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Validator] Check the BIC country with symfony/intl

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28167
| License       | MIT
| Doc PR        | N/A

Check the BIC country code against the list from Intl component instead of a simple check alphabetical test.

This PR uses the Intl component which is not part of the required dependencies of the Validator component (https://github.com/symfony/validator/blob/master/composer.json): `symfony/intl` is only required for dev. So I'm making a PR against master because it may break existing code.
But `CountryValidator` does the same so it may not be an issue after all.

Commits
-------

27bd3a8 [Validator] Check the BIC country with symfony/intl Fix #28167
@chalasr chalasr modified the milestones: 2.8, next Sep 20, 2018
@@ -63,7 +69,11 @@ public function validate($value, Constraint $constraint)
}

// next 2 letters must be alphabetic (country code)
if (!ctype_alpha(substr($canonicalize, 4, 2))) {
if (!class_exists(Intl::class)) {
Copy link
Member

Choose a reason for hiding this comment

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

IMO this is a BC break. The constraint was working without the Intl component before.

Copy link
Member

Choose a reason for hiding this comment

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

and this exception will only be thrown at runtime if no test covers its usage meaning that it will result in a server error which is not good from my point of view

Copy link
Member

Choose a reason for hiding this comment

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

I agree. Reading the issue, I thought this was accepted as a bugfix.
I'm going to submit a BC layer

symfony-splitter pushed a commit to symfony/validator that referenced this pull request Sep 30, 2018
…ntl (chalasr)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Validator] Add BC layer covering BicValidator without Intl

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#28473 (review)
| License       | MIT
| Doc PR        | n/a

Commits
-------

10b8a5f041 [Validator] Add BC layer covering BicValidator without Intl
fabpot added a commit that referenced this pull request Sep 30, 2018
…ntl (chalasr)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Validator] Add BC layer covering BicValidator without Intl

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #28473 (review)
| License       | MIT
| Doc PR        | n/a

Commits
-------

10b8a5f [Validator] Add BC layer covering BicValidator without Intl
@nicolas-grekas nicolas-grekas removed this from the next milestone Nov 1, 2018
@nicolas-grekas nicolas-grekas added this to the 4.2 milestone Nov 1, 2018
This was referenced Nov 3, 2018
@sylfabre sylfabre deleted the issue_28167 branch September 25, 2020 13:15
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.

None yet

5 participants