<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>yes</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.2.*</td>
</tr>
</tbody>
</table>
<p dir="auto">I am getting traffic from a web scanner who is sending crafted payloads to my form handlers. In particular, I'm getting arrays being sent to fields with email and regex validators, and my logs are being filled up with<br>
<code class="notranslate">UnexpectedTypeException: “Expected argument of type “string”, “array” given”</code></p>
<p dir="auto">Instead of throwing a type exception, the validators should gracefully return a violation</p>
<p dir="auto">I have this example, which i use in a small json-api where i use the form component to handle requests and validation.</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="-&gt;add('account', 'text', [
                'constraints' =&gt; [
                    new NotBlank(),
                    new Type('string'),
                    new Regex(&quot;/^XX\d+$/i&quot;)
                ]
            ])"><pre class="notranslate">-&gt;add(<span class="pl-s">'account'</span>, <span class="pl-s">'text'</span>, [
                <span class="pl-s">'constraints'</span> =&gt; [
                    <span class="pl-k">new</span> <span class="pl-v">NotBlank</span>(),
                    <span class="pl-k">new</span> <span class="pl-v">Type</span>(<span class="pl-s">'string'</span>),
                    <span class="pl-k">new</span> <span class="pl-v">Regex</span>("<span class="pl-s">/^XX\d+$/i</span>")
                ]
            ])</pre></div>
<p dir="auto">I have a form field for an accountname. The format of this name is <code class="notranslate">XX1234</code>.</p>
<p dir="auto">The validation above works great if the data being validated is a string. If i pass in an array instead of the string i will get an exception that is originating from here:</p>
<p dir="auto"><a href="https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Validator/Constraints/RegexValidator.php#L43">https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Validator/Constraints/RegexValidator.php#L43</a></p>
<p dir="auto">In my opinion the validation should just fail here instead of throwing an exception. I pass an array in, and try to run an regexp on it. It seems obvious to me that something is wrong with the input data then and the validation should fail.</p>
<p dir="auto">Other validation constraints seems to work this way. Look at this example:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="-&gt;add('disksize', 'text', [
                'constraints' =&gt; [
                    new NotBlank(),
                    new Type('numeric'),
                    new Range(['min' =&gt; 10, 'max' =&gt; 200])
                ]
            ])"><pre class="notranslate">-&gt;add(<span class="pl-s">'disksize'</span>, <span class="pl-s">'text'</span>, [
                <span class="pl-s">'constraints'</span> =&gt; [
                    <span class="pl-k">new</span> <span class="pl-v">NotBlank</span>(),
                    <span class="pl-k">new</span> <span class="pl-v">Type</span>(<span class="pl-s">'numeric'</span>),
                    <span class="pl-k">new</span> <span class="pl-v">Range</span>([<span class="pl-s">'min'</span> =&gt; <span class="pl-c1">10</span>, <span class="pl-s">'max'</span> =&gt; <span class="pl-c1">200</span>])
                ]
            ])</pre></div>
<p dir="auto">This works. I get an validation error and no exceptions. Other validations contraints, like <code class="notranslate">Length</code> seems to have the same problem as <code class="notranslate">Regex</code></p>
<p dir="auto">I think it would be great if all constraints just failed if they were passed an array if they cant handle an array. Or is there something i am overseeing?</p>
<p dir="auto">Is there some way i can work around this to make it fail validation if i pass in an array?</p>