Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Dec 13, 2022
1 parent fe71126 commit edd72e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,6 @@

public class UrlParser {

// TODO remove this unused?
@Nullable
public static String getAuthority(String url) {

int schemeEndIndexExclusive = getSchemeEndIndexExclusive(url);
if (schemeEndIndexExclusive == -1) {
// invalid url
return null;
}

int hostEndIndexExclusive = getHostEndIndexExclusive(url, schemeEndIndexExclusive);
if (hostEndIndexExclusive == schemeEndIndexExclusive) {
// no host (or port)
return null;
}

int portEndIndexExclusive = getPortEndIndexExclusive(url, hostEndIndexExclusive);

return url.substring(schemeEndIndexExclusive, portEndIndexExclusive);
}

@Nullable
public static String getTarget(String url) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,15 @@ public void testGetPathFromUrlWithPort() {
assertThat(UrlParser.getPath("https://localhost:8080/more/path/#fragment"))
.isEqualTo("/more/path/");
}

@Test
public void testGetPathFromMalformedUrl() {
assertThat(UrlParser.getPath("")).isNull();
assertThat(UrlParser.getPath("http:")).isNull();
assertThat(UrlParser.getPath("http:/")).isNull();
assertThat(UrlParser.getPath("http//")).isNull();
assertThat(UrlParser.getPath("http:localhost/path")).isNull();
assertThat(UrlParser.getPath("http:/localhost/path")).isNull();
assertThat(UrlParser.getPath("http//localhost/path")).isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,15 @@ public void testGetTargetFromUrlWithNoAuthority() {
assertThat(UrlParser.getTarget("https:/more/path#fragment")).isNull();
assertThat(UrlParser.getTarget("https:/more/path/#fragment")).isNull();
}

@Test
public void testGetTargetFromMalformedUrl() {
assertThat(UrlParser.getTarget("")).isNull();
assertThat(UrlParser.getTarget("http:")).isNull();
assertThat(UrlParser.getTarget("http:/")).isNull();
assertThat(UrlParser.getTarget("http//")).isNull();
assertThat(UrlParser.getTarget("http:localhost/path")).isNull();
assertThat(UrlParser.getTarget("http:/localhost/path")).isNull();
assertThat(UrlParser.getTarget("http//localhost/path")).isNull();
}
}

0 comments on commit edd72e3

Please sign in to comment.