glhd/laravel-addressing

country_code validation rule produces 500 error when an array is given

Closed this issue · 1 comments

suth commented

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'],

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