File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
main/java/emailvalidator4j/parser
test/java/emailvalidator4j/parser Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ public void parse(String domainPart) throws InvalidEmail {
5353
5454 private void doParseDomainPart () throws InvalidEmail {
5555 int domainPartOpenedParenthesis = 0 ;
56+ boolean openBrackets = false ;
5657 do {
5758 if (this .lexer .getCurrent ().equals (Tokens .SEMICOLON )) {
5859 throw new ExpectedATEXT ("Expected ATEXT" );
@@ -84,7 +85,8 @@ private void doParseDomainPart() throws InvalidEmail {
8485 this .checkConsecutiveDots ();
8586 this .checkExceptions ();
8687
87- if (this .lexer .getCurrent ().equals (Tokens .OPENBRACKET )) {
88+ if (isDomainLiteral (openBrackets )) {
89+ openBrackets = true ;
8890 this .parseLiteralPart ();
8991 }
9092
@@ -98,6 +100,14 @@ private void doParseDomainPart() throws InvalidEmail {
98100 } while (!this .lexer .isAtEnd ());
99101 }
100102
103+ private boolean isDomainLiteral (boolean openBrackets ) throws UnclosedDomainLiteral {
104+ if (this .lexer .getCurrent ().equals (Tokens .CLOSEBRACKET ) && !openBrackets ) {
105+ throw new UnclosedDomainLiteral ("Missing open bracket [" );
106+ }
107+
108+ return this .lexer .getCurrent ().equals (Tokens .OPENBRACKET );
109+ }
110+
101111 private void checkNotAllowedChars (TokenInterface token ) throws DomainNotAllowedCharacter {
102112 if (notAllowedTokens .contains (token )) {
103113 throw new DomainNotAllowedCharacter (
Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ public static Object[][] invalidDomainParts() {
4949 {DomainHyphen .class , "@atstart-.com" },
5050 {DomainNotAllowedCharacter .class , "@atst\\ art.com" },
5151 {DomainNotAllowedCharacter .class , "@example\\ " },
52- {DomainNotAllowedCharacter .class , "@exa\\ mple" }
52+ {DomainNotAllowedCharacter .class , "@exa\\ mple" },
53+ {UnclosedDomainLiteral .class , "@example]" },
5354 };
5455 }
5556
You can’t perform that action at this time.
0 commit comments