Skip to content

Commit

Permalink
HttpURI toURI passes all info (#11468)
Browse files Browse the repository at this point in the history
* HttpURI toURI passes all info

Fix #11465 and #7750
HttpURI.toURI user and fragment are retained.
Use to URI(String) constructor, as all URI constructors will parse the URI anyway.

* HttpURI toURI passes all info

Fix #11465 and #7750
HttpURI.toURI user and fragment are retained.
Use to URI(String) constructor, as all URI constructors will parse the URI anyway.
  • Loading branch information
gregw authored Feb 29, 2024
1 parent 561b8da commit 56e05a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.io.Serial;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
Expand All @@ -28,7 +27,6 @@
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.UrlEncoded;

/**
* Http URI.
Expand Down Expand Up @@ -263,15 +261,7 @@ default boolean hasUtf16Encoding()

default URI toURI()
{
try
{
String query = getQuery();
return new URI(getScheme(), null, getHost(), getPort(), getPath(), query == null ? null : UrlEncoded.decodeString(query), null);
}
catch (URISyntaxException x)
{
throw new RuntimeException(x);
}
return URI.create(toString());
}

class Immutable implements HttpURI, Serializable
Expand Down Expand Up @@ -511,19 +501,6 @@ public String toString()
{
return asString();
}

@Override
public URI toURI()
{
try
{
return new URI(_scheme, null, _host, URIUtil.normalizePortForScheme(_scheme, _port), _path, _query == null ? null : UrlEncoded.decodeString(_query), _fragment);
}
catch (URISyntaxException x)
{
throw new RuntimeException(x);
}
}
}

class Mutable implements HttpURI
Expand Down Expand Up @@ -980,18 +957,6 @@ public String toString()
return asString();
}

public URI toURI()
{
try
{
return new URI(_scheme, null, _host, _port, _path, _query == null ? null : UrlEncoded.decodeString(_query), null);
}
catch (URISyntaxException x)
{
throw new RuntimeException(x);
}
}

public Mutable uri(HttpURI uri)
{
_scheme = uri.getScheme();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void testBuilder()
.path("/ignored/../p%61th;ignored/info")
.param("param")
.query("query=value")
.fragment("fragment")
.asImmutable();

assertThat(uri.getScheme(), is("http"));
Expand All @@ -63,8 +64,10 @@ public void testBuilder()
assertThat(uri.getCanonicalPath(), is("/path/info"));
assertThat(uri.getParam(), is("param"));
assertThat(uri.getQuery(), is("query=value"));
assertThat(uri.getFragment(), is("fragment"));
assertThat(uri.getAuthority(), is("host:8888"));
assertThat(uri.toString(), is("http://user:password@host:8888/ignored/../p%61th;ignored/info;param?query=value"));
assertThat(uri.toString(), is("http://user:password@host:8888/ignored/../p%61th;ignored/info;param?query=value#fragment"));
assertThat(uri.toURI().toString(), is("http://user:password@host:8888/ignored/../p%61th;ignored/info;param?query=value#fragment"));

uri = HttpURI.build(uri)
.scheme("https")
Expand Down

0 comments on commit 56e05a9

Please sign in to comment.