You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@bval.apache.org by Matthew Adams <ma...@matthewadams.me> on 2013/02/28 22:33:32 UTC

Why does EmailValidator match null & ""?

Email validator seems to consider null and empty string ("") valid email.
 See
https://svn.apache.org/repos/asf/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java:

    public static boolean isValid(Object value, Pattern aPattern) {*
     if (value == null)
            return true;
        if (!(value instanceof CharSequence))
            return false;
        CharSequence seq = (CharSequence) value;
        if (seq.length() == 0)
            return true;*
        Matcher m = aPattern.matcher(seq);
        return m.matches();
    }

That surprises me.  Does it surprise anyone else?  Can we get that changed?
 I'd be happy to file an issue (and patch).

-matthew

-- 
mailto:matthew@matthewadams.me <ma...@matthewadams.me>
skype:matthewadams12
googletalk:matthew@matthewadams.me
http://matthewadams.me
http://www.linkedin.com/in/matthewadams

Re: Why does EmailValidator match null & ""?

Posted by Gerhard Petracek <ge...@gmail.com>.
or a custom composite constraint which is annotated with @Email and
@NotNull and (@Size or @NotEmpty)
(or a normal custom constraint which handles it differently)

regards,
gerhard



2013/2/28 Nick Chalko <nc...@google.com>

> in other words add
> @NotNull
>
>
> On Thu, Feb 28, 2013 at 2:18 PM, Gerhard Petracek <
> gerhard.petracek@gmail.com> wrote:
>
>> hi matthew,
>>
>> that's perfectly fine according to the specification.
>> handling null and empty values should be done by the
>> constraint-validator/s which are responsible for those values.
>>
>> regards,
>> gerhard
>>
>>
>>
>> 2013/2/28 Matthew Adams <ma...@matthewadams.me>
>>
>>> Email validator seems to consider null and empty string ("") valid
>>> email.  See
>>> https://svn.apache.org/repos/asf/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java:
>>>
>>>     public static boolean isValid(Object value, Pattern aPattern) {*        if (value == null)
>>>             return true;
>>>         if (!(value instanceof CharSequence))
>>>             return false;
>>>         CharSequence seq = (CharSequence) value;
>>>         if (seq.length() == 0)
>>>             return true;*
>>>         Matcher m = aPattern.matcher(seq);
>>>         return m.matches();
>>>     }
>>>
>>> That surprises me.  Does it surprise anyone else?  Can we get that
>>> changed?  I'd be happy to file an issue (and patch).
>>>
>>> -matthew
>>>
>>> --
>>> mailto:matthew@matthewadams.me <ma...@matthewadams.me>
>>> skype:matthewadams12
>>> googletalk:matthew@matthewadams.me
>>> http://matthewadams.me
>>> http://www.linkedin.com/in/matthewadams
>>>
>>
>>
>
>
> --
> Nick Chalko | Software Engineer | nchalko@google.com |   :-)
> Generate your java flags for easier testing.
> go/java_flags
>

Re: Why does EmailValidator match null & ""?

Posted by Nick Chalko <nc...@google.com>.
in other words add
@NotNull


On Thu, Feb 28, 2013 at 2:18 PM, Gerhard Petracek <
gerhard.petracek@gmail.com> wrote:

> hi matthew,
>
> that's perfectly fine according to the specification.
> handling null and empty values should be done by the
> constraint-validator/s which are responsible for those values.
>
> regards,
> gerhard
>
>
>
> 2013/2/28 Matthew Adams <ma...@matthewadams.me>
>
>> Email validator seems to consider null and empty string ("") valid email.
>>  See
>> https://svn.apache.org/repos/asf/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java:
>>
>>     public static boolean isValid(Object value, Pattern aPattern) {*        if (value == null)
>>             return true;
>>         if (!(value instanceof CharSequence))
>>             return false;
>>         CharSequence seq = (CharSequence) value;
>>         if (seq.length() == 0)
>>             return true;*
>>         Matcher m = aPattern.matcher(seq);
>>         return m.matches();
>>     }
>>
>> That surprises me.  Does it surprise anyone else?  Can we get that
>> changed?  I'd be happy to file an issue (and patch).
>>
>> -matthew
>>
>> --
>> mailto:matthew@matthewadams.me <ma...@matthewadams.me>
>> skype:matthewadams12
>> googletalk:matthew@matthewadams.me
>> http://matthewadams.me
>> http://www.linkedin.com/in/matthewadams
>>
>
>


-- 
Nick Chalko | Software Engineer | nchalko@google.com |   :-)
Generate your java flags for easier testing.
go/java_flags

Re: Why does EmailValidator match null & ""?

Posted by Gerhard Petracek <ge...@gmail.com>.
hi matthew,

that's perfectly fine according to the specification.
handling null and empty values should be done by the constraint-validator/s
which are responsible for those values.

regards,
gerhard



2013/2/28 Matthew Adams <ma...@matthewadams.me>

> Email validator seems to consider null and empty string ("") valid email.
>  See
> https://svn.apache.org/repos/asf/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java:
>
>     public static boolean isValid(Object value, Pattern aPattern) {*        if (value == null)
>             return true;
>         if (!(value instanceof CharSequence))
>             return false;
>         CharSequence seq = (CharSequence) value;
>         if (seq.length() == 0)
>             return true;*
>         Matcher m = aPattern.matcher(seq);
>         return m.matches();
>     }
>
> That surprises me.  Does it surprise anyone else?  Can we get that
> changed?  I'd be happy to file an issue (and patch).
>
> -matthew
>
> --
> mailto:matthew@matthewadams.me <ma...@matthewadams.me>
> skype:matthewadams12
> googletalk:matthew@matthewadams.me
> http://matthewadams.me
> http://www.linkedin.com/in/matthewadams
>