{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/9554","labels_url":"https://api.github.com/repos/laravel/framework/issues/9554/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/9554/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/9554/events","html_url":"https://github.com/laravel/framework/issues/9554","id":93561318,"number":9554,"title":"Regex validator throws exception if input isn't scalar","user":{"login":"curtisdf","id":1476787,"avatar_url":"https://avatars.githubusercontent.com/u/1476787?v=3","gravatar_id":"","url":"https://api.github.com/users/curtisdf","html_url":"https://github.com/curtisdf","followers_url":"https://api.github.com/users/curtisdf/followers","following_url":"https://api.github.com/users/curtisdf/following{/other_user}","gists_url":"https://api.github.com/users/curtisdf/gists{/gist_id}","starred_url":"https://api.github.com/users/curtisdf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/curtisdf/subscriptions","organizations_url":"https://api.github.com/users/curtisdf/orgs","repos_url":"https://api.github.com/users/curtisdf/repos","events_url":"https://api.github.com/users/curtisdf/events{/privacy}","received_events_url":"https://api.github.com/users/curtisdf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-07T15:43:39Z","updated_at":"2015-07-07T16:27:32Z","closed_at":null,"body":"The `regex` validator (and probably others) throws an exception if the input is not scalar.  Preceding the `regex` validation with a validation on the primitive data type (e.g. `string`) does not help since Laravel's validator runs all validations on a given field even if previous ones have failed. \r\nThis is with Laravel 5.1.1.  Example:\r\n\r\n```\r\n$data = ['foo' => ['La la la']];\r\n$rules = ['foo' => 'string|regex:/.*/'];\r\n$validator = Validator::make($data, $rules);\r\n$failed = $validator->fails();\r\n```\r\n\r\nRather than returning a boolean, $validator->fails() throws an exception in this case:\r\n\r\n```\r\nErrorException: preg_match() expects parameter 2 to be string, array given in \r\n{redacted}/vendor/illuminate/validation/Validator.php on line 1310\r\n```\r\n\r\nI would submit a pull request as the docs suggest, but I don't know what behavior is desired here.  Should the regex validator first check if the input is a string, and return false if not?  Personally, I would like to see the validator stop executing any subsequent validations on a field as soon as one of them fails, or at least for this to be a configurable option.  But it appears to be a firm design decision to run all validations no matter what.\r\n\r\nAlso, what about the other validators? I have not tested them, but I presume others are in a similar boat.\r\n"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/119260591","html_url":"https://github.com/laravel/framework/issues/9554#issuecomment-119260591","issue_url":"https://api.github.com/repos/laravel/framework/issues/9554","id":119260591,"user":{"login":"curtisdf","id":1476787,"avatar_url":"https://avatars.githubusercontent.com/u/1476787?v=3","gravatar_id":"","url":"https://api.github.com/users/curtisdf","html_url":"https://github.com/curtisdf","followers_url":"https://api.github.com/users/curtisdf/followers","following_url":"https://api.github.com/users/curtisdf/following{/other_user}","gists_url":"https://api.github.com/users/curtisdf/gists{/gist_id}","starred_url":"https://api.github.com/users/curtisdf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/curtisdf/subscriptions","organizations_url":"https://api.github.com/users/curtisdf/orgs","repos_url":"https://api.github.com/users/curtisdf/repos","events_url":"https://api.github.com/users/curtisdf/events{/privacy}","received_events_url":"https://api.github.com/users/curtisdf/received_events","type":"User","site_admin":false},"created_at":"2015-07-07T16:27:32Z","updated_at":"2015-07-07T16:27:32Z","body":"Ok.  So are you saying that the proper solution to avoid throwing those exceptions would be to make all validators gracefully fail if they are expecting scalar input but are given an array instead?\r\n"}}