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

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

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
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 12 src/Symfony/Component/Validator/Constraints/BicValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Intl\Intl;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
* @author Michael Hirschler <michael.vhirsch@gmail.com>
Expand All @@ -30,6 +32,10 @@ public function validate($value, Constraint $constraint)
return;
}

if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}

$canonicalize = str_replace(' ', '', $value);

// the bic must be either 8 or 11 characters long
Expand Down Expand Up @@ -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

throw new \LogicException('The "symfony/intl" component is required to use the Bic constraint.');
}
$countries = Intl::getRegionBundle()->getCountryNames();
if (!isset($countries[substr($canonicalize, 4, 2)])) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public function testEmptyStringIsValid()
$this->assertNoViolation();
}

/**
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
*/
public function testExpectsStringCompatibleType()
{
$this->validator->validate(new \stdClass(), new Bic());
}

/**
* @dataProvider getValidBics
*/
Expand Down Expand Up @@ -92,6 +100,7 @@ public function getInvalidBics()
array('DEUT12HH', Bic::INVALID_COUNTRY_CODE_ERROR),
array('DSBAC6BXSHA', Bic::INVALID_COUNTRY_CODE_ERROR),
array('DSBA5NBXSHA', Bic::INVALID_COUNTRY_CODE_ERROR),
array('DSBAAABXSHA', Bic::INVALID_COUNTRY_CODE_ERROR),

// branch code error
array('THISSVAL1D]', Bic::INVALID_CHARACTERS_ERROR),
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.