From 8b8c0ff3e6b4934c123849fa5b6704d29db579fc Mon Sep 17 00:00:00 2001 From: ruzann <40264956+ruzann@users.noreply.github.com> Date: Fri, 3 Aug 2018 12:54:37 +0400 Subject: [PATCH 1/8] Update InputTest.php --- test/InputTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/InputTest.php b/test/InputTest.php index 16ed313b..8bbdf183 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -329,7 +329,8 @@ public function testDefaultGetValue() public function testValueMayBeInjected() { - $valueRaw = $this->getDummyValue(); + $valueRaw = $this-> + (); $this->input->setValue($valueRaw); $this->assertEquals($valueRaw, $this->input->getValue()); @@ -941,7 +942,7 @@ protected function createNonEmptyValidatorMock($isValid, $value, $context = null protected function getDummyValue($raw = true) { if ($raw) { - return 'foo'; + return 'foo1'; } else { return 'filtered'; } From a0c9897d59d007deb95fa7f52567c1dfc02f8003 Mon Sep 17 00:00:00 2001 From: ruzann <40264956+ruzann@users.noreply.github.com> Date: Tue, 7 Aug 2018 10:30:00 +0400 Subject: [PATCH 2/8] Update InputTest.php --- test/InputTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/InputTest.php b/test/InputTest.php index 8bbdf183..16ed313b 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -329,8 +329,7 @@ public function testDefaultGetValue() public function testValueMayBeInjected() { - $valueRaw = $this-> - (); + $valueRaw = $this->getDummyValue(); $this->input->setValue($valueRaw); $this->assertEquals($valueRaw, $this->input->getValue()); @@ -942,7 +941,7 @@ protected function createNonEmptyValidatorMock($isValid, $value, $context = null protected function getDummyValue($raw = true) { if ($raw) { - return 'foo1'; + return 'foo'; } else { return 'filtered'; } From fabdf023979b14e53b0b3f31a884524eaee07805 Mon Sep 17 00:00:00 2001 From: ruzann <40264956+ruzann@users.noreply.github.com> Date: Mon, 15 Jul 2019 12:35:12 +0400 Subject: [PATCH 3/8] Create empty file structure if sent array for FileInput type --- src/FileInput/HttpServerFileInputDecorator.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/FileInput/HttpServerFileInputDecorator.php b/src/FileInput/HttpServerFileInputDecorator.php index 0e6323b7..2c7ee9b8 100644 --- a/src/FileInput/HttpServerFileInputDecorator.php +++ b/src/FileInput/HttpServerFileInputDecorator.php @@ -110,6 +110,15 @@ public function isValid($context = null) 'type' => '', 'error' => UPLOAD_ERR_NO_FILE, ]; + } elseif(!isset($rawValue['tmp_name']) || !isset($rawValue[0]['tmp_name'])) { + // This can happen when sent not file and just array + $rawValue = [ + 'tmp_name' => '', + 'name' => '', + 'size' => 0, + 'type' => '', + 'error' => UPLOAD_ERR_NO_FILE, + ]; } if (is_array($rawValue) && isset($rawValue['tmp_name'])) { From 3f2028d85f3951b46a45e4ac1f208d3c8b65e01e Mon Sep 17 00:00:00 2001 From: ruzann <40264956+ruzann@users.noreply.github.com> Date: Sun, 21 Jul 2019 21:56:41 +0400 Subject: [PATCH 4/8] Update HttpServerFileInputDecorator.php --- src/FileInput/HttpServerFileInputDecorator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FileInput/HttpServerFileInputDecorator.php b/src/FileInput/HttpServerFileInputDecorator.php index 2c7ee9b8..e418ec1a 100644 --- a/src/FileInput/HttpServerFileInputDecorator.php +++ b/src/FileInput/HttpServerFileInputDecorator.php @@ -110,7 +110,7 @@ public function isValid($context = null) 'type' => '', 'error' => UPLOAD_ERR_NO_FILE, ]; - } elseif(!isset($rawValue['tmp_name']) || !isset($rawValue[0]['tmp_name'])) { + } elseif(!isset($rawValue['tmp_name']) && !isset($rawValue[0]['tmp_name'])) { // This can happen when sent not file and just array $rawValue = [ 'tmp_name' => '', From cce322c2d5dda48cf51332f8cc94fcc1c7b5caf8 Mon Sep 17 00:00:00 2001 From: ruzann <40264956+ruzann@users.noreply.github.com> Date: Sun, 21 Jul 2019 22:01:51 +0400 Subject: [PATCH 5/8] Update HttpServerFileInputDecorator.php --- src/FileInput/HttpServerFileInputDecorator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FileInput/HttpServerFileInputDecorator.php b/src/FileInput/HttpServerFileInputDecorator.php index e418ec1a..b0034877 100644 --- a/src/FileInput/HttpServerFileInputDecorator.php +++ b/src/FileInput/HttpServerFileInputDecorator.php @@ -110,7 +110,7 @@ public function isValid($context = null) 'type' => '', 'error' => UPLOAD_ERR_NO_FILE, ]; - } elseif(!isset($rawValue['tmp_name']) && !isset($rawValue[0]['tmp_name'])) { + } elseif (! isset($rawValue['tmp_name']) && ! isset($rawValue[0]['tmp_name'])) { // This can happen when sent not file and just array $rawValue = [ 'tmp_name' => '', From 8fb4021071988444507979b30472705b24d852ae Mon Sep 17 00:00:00 2001 From: ruzann <40264956+ruzann@users.noreply.github.com> Date: Sun, 21 Jul 2019 22:16:28 +0400 Subject: [PATCH 6/8] created testValidationsRunWithoutFileArrayIsSend() --- .../HttpServerFileInputDecoratorTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/FileInput/HttpServerFileInputDecoratorTest.php b/test/FileInput/HttpServerFileInputDecoratorTest.php index bc935872..49e492bd 100644 --- a/test/FileInput/HttpServerFileInputDecoratorTest.php +++ b/test/FileInput/HttpServerFileInputDecoratorTest.php @@ -196,6 +196,23 @@ public function testValidationsRunWithoutFileArrayDueToAjaxPost() $this->assertFalse($this->input->isValid()); } + public function testValidationsRunWithoutFileArrayIsSend() + { + $this->input->setAutoPrependUploadValidator(true); + $this->assertTrue($this->input->getAutoPrependUploadValidator()); + $this->assertTrue($this->input->isRequired()); + $this->input->setValue([]); + $expectedNormalizedValue = [ + 'tmp_name' => '', + 'name' => '', + 'size' => 0, + 'type' => '', + 'error' => UPLOAD_ERR_NO_FILE, + ]; + $this->input->setValidatorChain($this->createValidatorChainMock([[$expectedNormalizedValue, null, false]])); + $this->assertFalse($this->input->isValid()); + } + public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null) { $this->markTestSkipped('Test is not enabled in FileInputTest'); From 2b4b984b5c2c0b1d010ea98471e5c270a4815fe4 Mon Sep 17 00:00:00 2001 From: ruzann <40264956+ruzann@users.noreply.github.com> Date: Sun, 21 Jul 2019 22:21:56 +0400 Subject: [PATCH 7/8] Update HttpServerFileInputDecoratorTest.php --- test/FileInput/HttpServerFileInputDecoratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/FileInput/HttpServerFileInputDecoratorTest.php b/test/FileInput/HttpServerFileInputDecoratorTest.php index 49e492bd..aed1b4ec 100644 --- a/test/FileInput/HttpServerFileInputDecoratorTest.php +++ b/test/FileInput/HttpServerFileInputDecoratorTest.php @@ -212,7 +212,7 @@ public function testValidationsRunWithoutFileArrayIsSend() $this->input->setValidatorChain($this->createValidatorChainMock([[$expectedNormalizedValue, null, false]])); $this->assertFalse($this->input->isValid()); } - + public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null) { $this->markTestSkipped('Test is not enabled in FileInputTest'); From 2ce5f2a0d99d994acf97205f454ba79be7cf60a8 Mon Sep 17 00:00:00 2001 From: webimpress Date: Wed, 28 Aug 2019 20:42:14 +0100 Subject: [PATCH 8/8] Adds CHANGELOG entry for #185 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcbedd35..16fe17f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed +- [#185](https://github.com/zendframework/zend-inputfilter/pull/185) fixes + validation response on invalid file upload request. + - [#181](https://github.com/zendframework/zend-inputfilter/pull/181) fixes missing abstract service factory registration in `Module` as per the [latest documentation](https://docs.zendframework.com/zend-inputfilter/specs/#setup).