Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpURI toURI passes all info #11468

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading