Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for dots in the local part of an e-mail address. #20

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ public enum ReaderNextState {
/**
* Finished reading, next step should be to read the query string.
*/
ReadQueryString
ReadQueryString,
/**
* Encountered an '@' while trying to read a domain name.
* We were possibly trying to read a domain name because we found a dot. But a dot is a common character
* in an e-mail address as well. If this case is not accounted for, things like [email protected] will be
* detected as
* http://first.last
* http://domain.com
*/
ReadUserPass
}

/**
Expand Down Expand Up @@ -332,6 +341,9 @@ public ReaderNextState readDomainName() {
} else if (curr == '#') {
//continue by reading the fragment
return checkDomainNameValid(ReaderNextState.ReadFragment, curr);
} else if (curr == '@') {
_buffer.append(curr);
return ReaderNextState.ReadUserPass;
} else if (CharUtils.isDot(curr)
|| (curr == '%' && _reader.canReadChars(2) && _reader.peek(2).equalsIgnoreCase(HEX_ENCODED_DOT))) {
//if the current character is a dot or a urlEncodedDot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ public void addCharacter(char character) {
}
});

//The start of where we are.
int startBufferLen = _buffer.length();

//Try to read the dns and act on the response.
DomainNameReader.ReaderNextState state = reader.readDomainName();
switch (state) {
Expand All @@ -547,6 +550,16 @@ public void addCharacter(char character) {
return readPort();
case ReadQueryString:
return readQueryString();
case ReadUserPass:
// found an '@' while trying to read a domain name. rollback, and try to read user/pass
_currentUrlMarker.unsetIndex(UrlPart.HOST);
int distance = _buffer.length() - startBufferLen;
_buffer.delete(startBufferLen, _buffer.length());

int currIndex = Math.max(_reader.getPosition() - distance, 0);
_reader.seek(currIndex);

return readUserPass(hostIndex);
default:
return readEnd(ReadEndState.InvalidUrl);
}
Expand Down
4 changes: 3 additions & 1 deletion url-detector/src/test/java/com/linkedin/urls/TestUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ private Object[][] getUsernamePasswordUrls() {
{"@www.google.com", "www.google.com", "/", "", ""},
{"lalal:@www.gogo.com", "www.gogo.com", "/", "lalal", ""},
{"nono:boo@[::1]", "[::1]", "/", "nono", "boo"},
{"nono:[email protected]/@1234", "yahoo.com", "/@1234", "nono", "boo"}
{"nono:[email protected]/@1234", "yahoo.com", "/@1234", "nono", "boo"},
{"[email protected]", "blah.com", "/", "fname.lname", ""},
{"[email protected]", "blah.com", "/", "fname.middle.lname", ""}
};
}

Expand Down