Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commitbb0e10e

Browse files
David Stocktonweierophinney
David Stockton
authored andcommitted
Bug/empty field crash for PATCH#88
No more stack trace when patch body has blank name field
1 parent4867403 commitbb0e10e

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

‎CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
###Fixed
2020

21-
- Nothing.
21+
-[#87] (https://github.com/zfcampus/zf-content-validation/issues/87) fixes patch with a
22+
blank field name causing a 400 error with a stack trace. It will now issue a 400 error with
23+
the message 'Unrecognized field ""'
2224

2325
##1.3.5 - 2016-08-18
2426

‎src/ContentValidationListener.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ protected function validatePatch(InputFilterInterface $inputFilter, $data, $isCo
470470
$inputFilter->setValidationGroup($validationGroup);
471471
return$inputFilter->isValid();
472472
}catch (InputFilterInvalidArgumentException$ex) {
473-
$pattern ='/expects a list of valid input names; "(?P<field>[^"]+)" was not found/';
473+
$pattern ='/expects a list of valid input names; "(?P<field>[^"]*)" was not found/';
474474
$matched =preg_match($pattern,$ex->getMessage(),$matches);
475-
if (!$matched) {
475+
if ($matched ===0) {
476476
returnnewApiProblemResponse(
477477
newApiProblem(400,$ex)
478478
);

‎test/ContentValidationListenerTest.php‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,44 @@ public function testFailsValidationOfPartialSetsForPatchRequestsThatIncludeUnkno
951951
return$response;
952952
}
953953

954+
publicfunctiontestFailsValidationOfPartialSetsForPatchRequestsThatIncludeBlankFieldNames()
955+
{
956+
$services =newServiceManager();
957+
$factory =newInputFilterFactory();
958+
$services->setService('FooValidator',$factory->createInputFilter([
959+
'foo' => [
960+
'name' =>'foo',
961+
'validators' => [
962+
['name' =>'Digits'],
963+
],
964+
],
965+
]));
966+
$listener =newContentValidationListener([
967+
'Foo' => ['input_filter' =>'FooValidator'],
968+
],$services);
969+
970+
$request =newHttpRequest();
971+
$request->setMethod('PATCH');
972+
973+
$matches =$this->createRouteMatch(['controller' =>'Foo']);
974+
975+
$dataParams =newParameterDataContainer();
976+
$dataParams->setBodyParams([
977+
'' =>true,
978+
]);
979+
980+
$event =newMvcEvent();
981+
$event->setRequest($request);
982+
$event->setRouteMatch($matches);
983+
$event->setParam('ZFContentNegotiationParameterData',$dataParams);
984+
985+
$response =$listener->onRoute($event);
986+
$this->assertInstanceOf(ApiProblemResponse::class,$response);
987+
$innerProblem =$response->getApiProblem();
988+
$this->assertEquals(400,$innerProblem->status);
989+
$this->assertEquals('Unrecognized field ""',$innerProblem->detail);
990+
}
991+
954992
/**
955993
* @depends testFailsValidationOfPartialSetsForPatchRequestsThatIncludeUnknownInputs
956994
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp