Skip to content

Commit

Permalink
While detecting Username and password in url we were not breaking the… (
Browse files Browse the repository at this point in the history
#31)

* While detecting Username and password in url we were not breaking the iteration if we find the :
This meanst that if there was a long substring of : then we will iterate till the end of the : string
and then restart the same iteration for the next :.
This fix breaks the usename and password detection when it encounters the next : thus breaking the look early
and backtracking less.

* Adding a test case for a valid URL between colons
  • Loading branch information
KanishkRastogi-lnkd authored May 7, 2020
1 parent 37a1e0f commit 173c6db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion url-detector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.linkedin.urls</groupId>
<artifactId>url-detector</artifactId>
<version>0.2.1-alpha</version>
<version>0.2.2-alpha</version>
<packaging>jar</packaging>

<name>com.linkedin.urls:url-detector</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private boolean readUserPass(int beginningOfUsername) {
//everything is still ok, just remember that we found a dot or '[' in case we might need to backtrack
_buffer.append(curr);
rollback = true;
} else if (curr == '#' || curr == ' ' || curr == '/'
} else if (curr == '#' || curr == ' ' || curr == '/' || curr ==':'
|| checkMatchingCharacter(curr) != CharacterMatch.CharacterNotMatched) {
//one of these characters indicates we are invalid state and should just return.
rollback = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,23 @@ public void testIpv6ZoneIndicesWithUrlEncodedDots(String address, String zoneInd
runTest(validUrl, UrlDetectorOptions.Default, validUrl);
}

@Test
public void testColonEmbededurl() {
runTest("::::::::::::::::::::::http://username:[email protected]:::::::::::::::",
UrlDetectorOptions.Default, "http://username:[email protected]");
}
@Test
public void testNegativeArraySizeException() {
String rawtext = "How ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\\n\\nCome ";
List<Url> urls = null;
try {
UrlDetector detector = new UrlDetector(rawtext, UrlDetectorOptions.Default);
urls = detector.detect();
} catch (NegativeArraySizeException e ) {
Assert.fail(e.getMessage());
}
}

@Test
public void testBacktrackInvalidUsernamePassword() {
runTest("http://hello:asdf.com", UrlDetectorOptions.Default, "asdf.com");
Expand Down

1 comment on commit 173c6db

@pgalbraith
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a fork of this project at https://github.com/URL-Detector/URL-Detector which fixes several other issues as well, since the issues were lingering here without attention for several years. Is there any interest at LinkedIn in trying to unify these back into a single codebase?

Please sign in to comment.