Skip to content

Commit

Permalink
Merge pull request #28 from sideshowbarker/master
Browse files Browse the repository at this point in the history
Prevent NPE for relative fragment w/ base != null.
  • Loading branch information
smola committed Mar 12, 2014
2 parents 819cc1d + cb2907d commit 5ffa96c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/io/mola/galimatias/URLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ else if (c == '#') {
host = (base == null)? null : base.host();
port = (base == null || base.port() == base.defaultPort())? -1 : base.port();
pathSegments = (base == null)? null : base.pathSegments();
query = (base == null)? null : new StringBuilder(base.query());
query = (base == null || base.query() == null)? null : new StringBuilder(base.query());
fragment = new StringBuilder();
state = ParseURLState.FRAGMENT;
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/io/mola/galimatias/URL2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ public void testRelativeWithScheme() throws Exception {
assertEquals("http://host/", URL.parse(base, "http:/").toString());
}

public void testRelativeFragmentOnly() throws Exception {
URL base = URL.parse("http://host/a/b/c");
assertEquals("http://host/a/b/c#", URL.parse(base, "#").toString());
}

public void testMalformedUrlsRefusedByFirefoxAndChrome() throws Exception {
URL base = URL.parse("http://host/a/b/c");
// All these are Ok in android, not in galimatias
Expand Down

0 comments on commit 5ffa96c

Please sign in to comment.