Skip to content

Commit

Permalink
fix for linkedin#13
Browse files Browse the repository at this point in the history
  • Loading branch information
pgalbraith authored and cstroe committed Nov 4, 2018
1 parent 940784b commit 25f8008
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/main/java/com/linkedin/urls/detection/DomainNameReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ public enum ReaderNextState {
/**
* Finished reading, next step should be to read the query string.
*/
ReadQueryString
ReadQueryString,
/**
* This was actually not a domain at all.
*/
ReadUserPass
}

/**
Expand Down Expand Up @@ -332,6 +336,10 @@ public ReaderNextState readDomainName() {
} else if (curr == '#') {
//continue by reading the fragment
return checkDomainNameValid(ReaderNextState.ReadFragment, curr);
} else if (curr == '@') {
//this may not have been a domain after all, but rather a username/password instead
_reader.goBack();
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
4 changes: 4 additions & 0 deletions src/main/java/com/linkedin/urls/detection/UrlDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ public void addCharacter(char character) {
return readPort();
case ReadQueryString:
return readQueryString();
case ReadUserPass:
int host = _currentUrlMarker.indexOf(UrlPart.HOST);
_currentUrlMarker.unsetIndex(UrlPart.HOST);
return readUserPass(host);
default:
return readEnd(ReadEndState.InvalidUrl);
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/linkedin/urls/TestUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ 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]", "google.com", "/", "big.big.boss", ""}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public void testIssue13() {
runTest("[email protected]", UrlDetectorOptions.Default, "[email protected]");
runTest("first.middle.reallyreallyreallyreallyreallyreallyreallyreallyreallyreallylonglastname@gmail.com", UrlDetectorOptions.Default, "first.middle.reallyreallyreallyreallyreallyreallyreallyreallyreallyreallylonglastname@gmail.com");
}

/*
* https://github.com/linkedin/URL-Detector/issues/15
*/
Expand Down

0 comments on commit 25f8008

Please sign in to comment.