Skip to content

Commit

Permalink
less strict validation of email addresses
Browse files Browse the repository at this point in the history
E-mail addresses are currently validated with classes provided by [commons-validator](https://commons.apache.org/validator/) when XML is read or written. This validator does not handle new top level domains (nTLD) properly. Therefore the validation is replaced by a more simple approach, that validates the e-mail address against the pattern, that is specified by IS24 in `common-1.0.xsd`.

```
  <xs:simpleType name="Email">
    <xs:annotation>
      <xs:documentation xml:lang="en">Common email address with restriction of 300 chars.</xs:documentation>
      <xs:documentation xml:lang="de-DE">Emailadresse mit einer 300 Zeichen Längenbegrenzung.
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:minLength value="5"/>
      <xs:maxLength value="300"/>
      <xs:pattern value=".+@.+\..+"></xs:pattern>
    </xs:restriction>
  </xs:simpleType>
```
  • Loading branch information
pinhead84 committed Mar 11, 2016
1 parent a4d2e31 commit 643a2a0
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 1,029 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Expand Up @@ -5,7 +5,21 @@ Changelog for OpenEstate-IS24-REST
0.4-SNAPSHOT (not released yet)
-------------------------------

...
### bugfixes

- Less strict validation of e-mail addresses.
E-mail addresses are currently validated with classes provided by
[commons-validator](https://commons.apache.org/validator/) when XML is read
or written. This validator does not handle new top level domains (nTLD)
properly. Therefore the validation is replaced by a more simple approach,
that validates the e-mail address against the pattern, that is specified by
IS24 in `common-1.0.xsd`.

### updates

- The package `org.openestate.is24.restapi.utils.validator`, that contains
some classes of [commons-validator](https://commons.apache.org/validator/),
was removed from source code.


0.3.1 (10 Mar 2016)
Expand Down
Expand Up @@ -45,7 +45,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.openestate.is24.restapi.utils.validator.EmailValidator;
import org.openestate.is24.restapi.xml.common.Attachment;
import org.openestate.is24.restapi.xml.common.City;
import org.openestate.is24.restapi.xml.common.Continent;
Expand Down Expand Up @@ -107,6 +106,8 @@ public final class XmlUtils
"<[^<>\\n]*>", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE );
private final static Pattern BR_TAG_PATTERN = Pattern.compile(
"<\\s*br[^<>\\n]*>", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE );
private final static Pattern EMAIL_PATTERN = Pattern.compile(
".+@.+\\..+", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE );

private XmlUtils()
{
Expand Down Expand Up @@ -430,7 +431,7 @@ public static String parseEmail( String value )
{
String val = parseText( value, 5, 300 );
if (val==null) return null;
return (EmailValidator.getInstance().isValid( val ))? val: null;
return (EMAIL_PATTERN.matcher( val ).matches())? val: null;
}

/**
Expand Down Expand Up @@ -1193,7 +1194,7 @@ public static String printDecimalPositive( BigDecimal value )
public static String printEmail( String value )
{
String val = printText( value, 5, 300 );
if (val==null || !EmailValidator.getInstance().isValid( val ))
if (val==null || !EMAIL_PATTERN.matcher( val ).matches())
{
throw new IllegalArgumentException(
"The provided email '" + value + "' is invalid!" );
Expand Down

0 comments on commit 643a2a0

Please sign in to comment.