Skip to content

Commit

Permalink
Merge pull request #80 from laminas/2.13.x-merge-up-into-2.14.x_5ff5d…
Browse files Browse the repository at this point in the history
…1a8c23aa5.03785754

Merge release 2.13.5 into 2.14.x
  • Loading branch information
weierophinney committed Jan 6, 2021
2 parents 83c2a96 + 8ac1c08 commit a21645e
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 204 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Expand Up @@ -24,6 +24,20 @@ All notable changes to this project will be documented in this file, in reverse

- Nothing.

## 2.13.5 - 2021-01-06

### Release Notes for [2.13.5](https://github.com/laminas/laminas-validator/milestone/4)

- Total issues resolved: **0**
- Total pull requests resolved: **3**
- Total contributors: **2**

#### Bug

- [68: Remove duplicate keys in ValidatorPluginManager::factories](https://github.com/laminas/laminas-validator/pull/68) thanks to @samsonasik
- [67: Possible fixes #8 compilation failed regex too large](https://github.com/laminas/laminas-validator/pull/67) thanks to @samsonasik
- [62: qa: Replace array by data providers in unit tests](https://github.com/laminas/laminas-validator/pull/62) thanks to @codisart

## 2.13.4 - 2020-03-31

### Added
Expand Down
8 changes: 8 additions & 0 deletions src/Hostname.php
Expand Up @@ -1977,6 +1977,14 @@ public function isValid($value)
return true;
}

// Handle Regex compilation failure that may happen on .biz domain with has @ character, eg: tapi4457@hsoqvf.biz
// Technically, hostname with '@' character is invalid, so mark as invalid immediately
// @see https://github.com/laminas/laminas-validator/issues/8
if (strpos($value, '@') !== false) {
$this->error(self::INVALID_HOSTNAME);
return false;
}

// Local hostnames are allowed to be partial (ending '.')
if ($this->getAllow() & self::ALLOW_LOCAL) {
if (substr($value, -1) === '.') {
Expand Down
40 changes: 22 additions & 18 deletions test/DigitsTest.php
Expand Up @@ -16,9 +16,7 @@
*/
class DigitsTest extends TestCase
{
/**
* @var Digits
*/
/** @var Digits */
protected $validator;

protected function setUp() : void
Expand All @@ -29,24 +27,30 @@ protected function setUp() : void
/**
* Ensures that the validator follows expected behavior for basic input values
*
* @dataProvider basicDataProvider
* @return void
*/
public function testExpectedResultsWithBasicInputValues()
public function testExpectedResultsWithBasicInputValues(string $input, bool $expected)
{
$valuesExpected = [
'abc123' => false,
'abc 123' => false,
'abcxyz' => false,
'AZ@#4.3' => false,
'1.23' => false,
'0x9f' => false,
'123' => true,
'09' => true,
'' => false,
];
foreach ($valuesExpected as $input => $result) {
$this->assertEquals($result, $this->validator->isValid($input));
}
$this->assertSame($expected, $this->validator->isValid($input));
}

public function basicDataProvider()
{
return [
// phpcs:disable
'invalid; starts with alphabetic chars' => ['abc123', false],
'invalid; contains alphabetic chars and one whitespace' => ['abc 123', false],
'invalid; contains only alphabetic chars' => ['abcxyz', false],
'invalid; contains alphabetic and special chars' => ['AZ@#4.3', false],
'invalid; is a float' => ['1.23', false],
'invalid; is a hexa notation' => ['0x9f', false],
'invalid; is empty' => ['', false],

'valid; is a normal integer' => ['123', true],
'valid; starts with a zero' => ['09', true],
// phpcs:enable
];
}

/**
Expand Down
65 changes: 33 additions & 32 deletions test/File/CountTest.php
Expand Up @@ -21,41 +21,42 @@ class CountTest extends TestCase
/**
* Ensures that the validator follows expected behavior
*
* @dataProvider basicDataProvider
* @param array|int $options
* @return void
*/
public function testBasic()
public function testBasic($options, bool $expected1, bool $expected2, bool $expected3, bool $expected4)
{
$valuesExpected = [
[5, true, true, true, true],
[['min' => 0, 'max' => 3], true, true, true, false],
[['min' => 2, 'max' => 3], false, true, true, false],
[['min' => 2], false, true, true, true],
[['max' => 5], true, true, true, true],
];

foreach ($valuesExpected as $element) {
$validator = new File\Count($element[0]);
$this->assertEquals(
$element[1],
$validator->isValid(__DIR__ . '/_files/testsize.mo'),
'Tested with ' . var_export($element, 1)
);
$this->assertEquals(
$element[2],
$validator->isValid(__DIR__ . '/_files/testsize2.mo'),
'Tested with ' . var_export($element, 1)
);
$this->assertEquals(
$element[3],
$validator->isValid(__DIR__ . '/_files/testsize3.mo'),
'Tested with ' . var_export($element, 1)
);
$this->assertEquals(
$element[4],
$validator->isValid(__DIR__ . '/_files/testsize4.mo'),
'Tested with ' . var_export($element, 1)
);
}
$validator = new File\Count($options);
$this->assertSame(
$expected1,
$validator->isValid(__DIR__ . '/_files/testsize.mo')
);
$this->assertSame(
$expected2,
$validator->isValid(__DIR__ . '/_files/testsize2.mo')
);
$this->assertSame(
$expected3,
$validator->isValid(__DIR__ . '/_files/testsize3.mo')
);
$this->assertSame(
$expected4,
$validator->isValid(__DIR__ . '/_files/testsize4.mo')
);
}

public function basicDataProvider()
{
return [
// phpcs:disable
'no minimum; maximum: 5; integer' => [5, true, true, true, true],
'no minimum; maximum: 5; array' => [['max' => 5], true, true, true, true],
'minimum: 0; maximum: 3' => [['min' => 0, 'max' => 3], true, true, true, false],
'minimum: 2; maximum: 3' => [['min' => 2, 'max' => 3], false, true, true, false],
'minimum: 2; no maximum' => [['min' => 2], false, true, true, true],
// phpcs:enable
];
}

/**
Expand Down
74 changes: 41 additions & 33 deletions test/File/FilesSizeTest.php
Expand Up @@ -28,50 +28,58 @@ protected function setUp() : void
/**
* Ensures that the validator follows expected behavior
*
* @dataProvider basicDataProvider
* @param array|int $options
* @return void
*/
public function testBasic()
public function testBasic($options, bool $expected1, bool $expected2, bool $expected3)
{
$valuesExpected = [
[['min' => 0, 'max' => 2000], true, true, false],
[['min' => 0, 'max' => '2 MB'], true, true, true],
[['min' => 0, 'max' => '2MB'], true, true, true],
[['min' => 0, 'max' => '2 MB'], true, true, true],
[2000, true, true, false],
[['min' => 0, 'max' => 500], false, false, false],
[500, false, false, false],
];

foreach ($valuesExpected as $element) {
$validator = new File\FilesSize($element[0]);
$this->assertEquals(
$element[1],
$validator->isValid(__DIR__ . '/_files/testsize.mo'),
'Tested with ' . var_export($element, 1)
);
$this->assertEquals(
$element[2],
$validator->isValid(__DIR__ . '/_files/testsize2.mo'),
'Tested with ' . var_export($element, 1)
);
$this->assertEquals(
$element[3],
$validator->isValid(__DIR__ . '/_files/testsize3.mo'),
'Tested with ' . var_export($element, 1)
);
}
$validator = new File\FilesSize(...$options);
$this->assertSame(
$expected1,
$validator->isValid(__DIR__ . '/_files/testsize.mo')
);
$this->assertSame(
$expected2,
$validator->isValid(__DIR__ . '/_files/testsize2.mo')
);
$this->assertSame(
$expected3,
$validator->isValid(__DIR__ . '/_files/testsize3.mo')
);
}

$validator = new File\FilesSize(['min' => 0, 'max' => 200]);
$this->assertEquals(false, $validator->isValid(__DIR__ . '/_files/nofile.mo'));
$this->assertArrayHasKey('fileFilesSizeNotReadable', $validator->getMessages());
public function basicDataProvider()
{
return [
// phpcs:disable
'minimum: 0 byte; maximum: 500 bytes; integer' => [[500], false, false, false],
'minimum: 0 byte; maximum: 500 bytes; array' => [[['min' => 0, 'max' => 500]], false, false, false],
'minimum: 0 byte; maximum: 2000 bytes; integer' => [[2000], true, true, false],
'minimum: 0 byte; maximum: 2000 bytes; array' => [[['min' => 0, 'max' => 2000]], true, true, false],
'minimum: 0 byte; maximum: 500 kilobytes' => [[['min' => 0, 'max' => 500000]], true, true, true],
'minimum: 0 byte; maximum: 2 megabytes; 2 MB' => [[['min' => 0, 'max' => '2 MB']], true, true, true],
'minimum: 0 byte; maximum: 2 megabytes; 2MB' => [[['min' => 0, 'max' => '2MB']], true, true, true],
'minimum: 0 byte; maximum: 2 megabytes; 2 MB' => [[['min' => 0, 'max' => '2 MB']], true, true, true],
// phpcs:enable
];
}

public function testMultipleFiles()
{
$validator = new File\FilesSize(['min' => 0, 'max' => 500000]);
$this->assertEquals(true, $validator->isValid([
__DIR__ . '/_files/testsize.mo',
__DIR__ . '/_files/testsize.mo',
__DIR__ . '/_files/testsize2.mo',
]));
$this->assertEquals(true, $validator->isValid(__DIR__ . '/_files/testsize.mo'));
}

public function testFileDoNotExist()
{
$validator = new File\FilesSize(['min' => 0, 'max' => 200]);
$this->assertEquals(false, $validator->isValid(__DIR__ . '/_files/nofile.mo'));
$this->assertArrayHasKey('fileFilesSizeNotReadable', $validator->getMessages());
}

/**
Expand Down

0 comments on commit a21645e

Please sign in to comment.