Skip to content

Commit

Permalink
Merge branch 'issue-99/optional-arguments-fail-if-non-latin'
Browse files Browse the repository at this point in the history
Fixes #99 and closes PR #100 with many thanks to @robmeek and @fidelo-software for giving me their feedback. 👍
  • Loading branch information
DragonBe committed May 27, 2020
2 parents ef13d82 + e72bef3 commit 46c9de6
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Vies/Vies.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private function addOptionalArguments(array &$requestParams, string $argumentKey
private function filterArgument(string $argumentValue): string
{
$argumentValue = str_replace(['"', '\''], '', $argumentValue);
return filter_var($argumentValue, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_HIGH);
return filter_var($argumentValue, FILTER_SANITIZE_STRIPPED, FILTER_FLAG_STRIP_LOW);
}

/**
Expand All @@ -398,8 +398,9 @@ private function filterArgument(string $argumentValue): string
*/
private function validateArgument(string $argumentValue): bool
{
$regexp = '/^[a-zA-Z0-9\s\.\-,&\+\(\)\/º\pL]+$/u';
if (false === filter_var($argumentValue, FILTER_VALIDATE_REGEXP, [
'options' => ['regexp' => '/^[a-zA-Z0-9\s\.\-,]+$/']
'options' => ['regexp' => $regexp]
])) {
return false;
}
Expand Down
136 changes: 136 additions & 0 deletions tests/Vies/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,140 @@ public function testVatNumberChecksumFailure()
}
}
}

public function traderDataProvider()
{
return [
'Belgian Trader Name' => [
[
'countryCode' => 'BE',
'vatNumber' => '0203430576',
'requesterCountryCode' => 'BE',
'requesterVatNumber' => '0203430576',
'traderName' => 'B-Rail',
'traderCompanyType' => 'NV',
'traderStreet' => 'Frankrijkstraat 65',
'traderPostcode' => '1060',
'traderCity' => 'Sint-Gillis',
],
],
'German Trader Name' => [
[
'countryCode' => 'DE',
'vatNumber' => '811569869',
'requesterCountryCode' => 'DE',
'requesterVatNumber' => '811569869',
'traderName' => 'Deutsche Bahn',
'traderCompanyType' => 'AG',
'traderStreet' => 'Potsdamer Platz 2',
'traderPostcode' => '10785',
'traderCity' => 'Berlin',
],
],
'Greek Trader Name' => [
[
'countryCode' => 'EL',
'vatNumber' => '999645865',
'requesterCountryCode' => 'EL',
'requesterVatNumber' => '999645865',
'traderName' => 'ΤΡΑΙΝΟΣΕ',
'traderCompanyType' => 'AE',
'traderStreet' => 'ΚΑΡΟΛΟΥ 1-3',
'traderPostcode' => '10437',
'traderCity' => 'ΑΘΗΝΑ',
],
],
'Polish Trader Name' => [
[
'countryCode' => 'PL',
'vatNumber' => '1132316427',
'requesterCountryCode' => 'PL',
'requesterVatNumber' => '1132316427',
'traderName' => 'PKP POLSKIE LINIE KOLEJOWE SPÓŁKA AKCYJNA',
'traderCompanyType' => '',
'traderStreet' => 'TARGOWA 74',
'traderPostcode' => '03-734',
'traderCity' => 'WARSZAWA',
],
],
'Ampesant Trader Name' => [
[
'countryCode' => 'BE',
'vatNumber' => '0458591947',
'requesterCountryCode' => 'BE',
'requesterVatNumber' => '0458591947',
'traderName' => 'VAN AERDE & PARTNERS',
'traderCompanyType' => 'BVBA',
'traderStreet' => 'RIJSELSTRAAT 274',
'traderPostcode' => '8200',
'traderCity' => 'BRUGGE',
],
],
'Dot-dash Trader Name' => [
[
'countryCode' => 'BE',
'vatNumber' => '0467609086',
'requesterCountryCode' => 'BE',
'requesterVatNumber' => '0467609086',
'traderName' => 'HAELTERMAN C.V.-KLIMA',
'traderCompanyType' => 'BVBA',
'traderStreet' => 'GERAARDSBERGSESTEENWEG 307',
'traderPostcode' => '9404',
'traderCity' => 'NINOVE',
],
],
'Accent Trader Name' => [
[
'countryCode' => 'BE',
'vatNumber' => '0873284862',
'requesterCountryCode' => 'BE',
'requesterVatNumber' => '0873284862',
'traderName' => '\'t GERIEF',
'traderCompanyType' => 'CVBA',
'traderStreet' => 'LICHTAARTSEWEG(HRT) 22',
'traderPostcode' => '2200',
'traderCity' => 'HERENTALS',
],
],
'Plus Trader Name' => [
[
'countryCode' => 'BE',
'vatNumber' => '0629758840',
'requesterCountryCode' => 'BE',
'requesterVatNumber' => '0629758840',
'traderName' => 'ARCHITECTUUR+',
'traderCompanyType' => 'BVBA',
'traderStreet' => 'STATIONSSTRAAT 28',
'traderPostcode' => '3930',
'traderCity' => 'HAMONT-ACHEL',
],
],
];
}

/**
* Testing that arguments that contain non-latin values are still
* validated correctly
*
* @group issue-99
* @covers \DragonBe\Vies\Vies::validateVat
* @covers \DragonBe\Vies\Vies::validateArgument
* @dataProvider TraderDataProvider
*/
public function testArgumentValidationSucceedsForNonLatinArgumentValues(array $traderData)
{
$vies = new Vies();
$vatResponse = $vies->validateVat(
$traderData['countryCode'],
$traderData['vatNumber'],
$traderData['requesterCountryCode'],
$traderData['requesterVatNumber'],
$traderData['traderName'],
$traderData['traderCompanyType'],
$traderData['traderStreet'],
$traderData['traderPostcode'],
$traderData['traderCity']
);
$this->assertTrue($vatResponse->isValid());
}
}
8 changes: 0 additions & 8 deletions tests/Vies/ViesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,6 @@ public function badOptionalInformationProvider(): array
'1000',
'Some Town',
],
[
'HackThePlanet',
'Ltd',
'Main Street 1',
'1000<?php echo url_decode("%3c%73%63%72%69%70%74%3e%61%6c%65%72%74%28%22%78'
. '%73%73%22%29%3b%3c%2f%73%63%72%69%70%74%3e") ?>',
'Some Town',
],
[
'HackThePlanet',
'Ltd',
Expand Down

0 comments on commit 46c9de6

Please sign in to comment.