mvlabs / ze-content-validation

Middleware for automating validation of incoming input.
http://www.mvlabs.it
8 stars 7 forks source link

Exception when body is empty #13

Open whites11 opened 6 years ago

whites11 commented 6 years ago

I am using this project to check the correctness of the query string parameters of a PUT call which is body-less by design. I understand this is an edge case, but this is throwing an exception.

ZE\ContentValidation\Exception\UnexpectedValueException: Data Extractor `ZE\ContentValidation\Extractor\BodyExtractor` returned a `NULL` instead of an `array`
 in: /app/src/vendor/mvlabs/ze-content-validation/src/Extractor/DataExtractorChain.php: 54
#0 [internal function]: ZE\ContentValidation\Extractor\DataExtractorChain->ZE\ContentValidation\Extractor\{closure}(Object(ZE\ContentValidation\Extractor\BodyExtractor))
#1 /app/src/vendor/mvlabs/ze-content-validation/src/Extractor/DataExtractorChain.php(64): array_map(Object(Closure), Array)
#2 /app/src/vendor/mvlabs/ze-content-validation/src/Validator/ValidatorHandler.php(71): ZE\ContentValidation\Extractor\DataExtractorChain->getDataFromRequest(Object(Zend\Diactoros\ServerRequest))
#3 /app/src/vendor/mvlabs/ze-content-validation/src/Middleware/ValidationMiddleware.php(53): ZE\ContentValidation\Validator\ValidatorHandler->validate(Object(Zend\Diactoros\ServerRequest))
#4 /app/src/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php(60): 

Maybe it would make sense to treath the "null" case as a special case returning an empty array in the BodyExtractor class

jguittard commented 5 years ago

Why would a PUT call would be body less by design ?