glhd / laravel-addressing

Laravel package providing addressing functionality
MIT License
62 stars 14 forks source link

country_code validation rule produces 500 error when an array is given #11

Closed suth closed 5 years ago

suth commented 5 years ago

I was writing some feature tests to ensure that my app handles unexpected input gracefully, and I noticed that if I send an array in place of the country code I get a 500 response instead of 422. This happens because of the call strtoupper() on the input here. I'd be happy to create a PR with some tests and a fix but thought I'd go ahead an open an issue.

Here's a simplified recreation of my feature test failing:

// Inside my test
$this->json('POST', '/api/v1/order', [
    'country_code' => ['this', 'is', 'an', 'array']
])->assertStatus(422);

// Using these validation rules causes 500
'country_code' => ['required', 'string', 'country_code'],

// My temporary workaround using 'bail'
'country_code' => ['required', 'string', 'bail', 'country_code'],
inxilpro commented 5 years ago

Thanks! You’re definitely welcome to submit a PR.