Skip to content

Commit

Permalink
Fixes problems converting a ClientUri to a URI. Improved test.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
  • Loading branch information
spericas committed Jan 30, 2024
1 parent 0be9a97 commit b10b661
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,7 +79,7 @@ public UriQueryWriteable from(UriQuery uriQuery) {
.addAll(raw);
List<String> decoded = uriQuery.all(name);
decodedQueryParams.computeIfAbsent(name, it -> new ArrayList<>())
.addAll(raw);
.addAll(decoded);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ public void testBasicPost() {
@Test
public void queryGetTest() {
try (Response response = target("basic").path("getquery")
.queryParam("first", "hello there ")
.queryParam("second", "world")
.queryParam("first", "\"hello there ")
.queryParam("second", "world\"")
.request().get()) {
assertThat(response.getStatus(), is(200));
assertThat(response.readEntity(String.class), is("hello there world"));
assertThat(response.readEntity(String.class), is("\"hello there world\""));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -103,15 +103,16 @@ public String toString() {
}

/**
* Convert instance to {@link java.net.URI}.
* Convert instance to {@link java.net.URI}. Note that we must use raw here
* to make sure no illegal URL characters are passed to the create method.
*
* @return the converted URI
*/
public URI toUri() {
UriInfo info = uriBuilder.build();
return URI.create(info.scheme() + "://"
+ info.authority()
+ pathWithQueryAndFragment());
+ pathWithQueryAndFragment(false)); // URI needs encoded
}

/**
Expand Down Expand Up @@ -293,15 +294,20 @@ public UriQueryWriteable writeableQuery() {
}

/**
* Encoded path with query and fragment.
* Path with query and fragment. Result is encoded or decoded depending on the
* value of {@link #skipUriEncoding}.
*
* @return string containing encoded path with query
* @return string containing path with query
*/
public String pathWithQueryAndFragment() {
return pathWithQueryAndFragment(skipUriEncoding);
}

private String pathWithQueryAndFragment(boolean decoded) {
UriInfo info = uriBuilder.query(query).build();

String queryString = skipUriEncoding ? info.query().value() : info.query().rawValue();
String path = skipUriEncoding ? info.path().path() : info.path().rawPath();
String queryString = decoded ? info.query().value() : info.query().rawValue();
String path = decoded ? info.path().path() : info.path().rawPath();

boolean hasQuery = !queryString.isEmpty();

Expand All @@ -314,7 +320,7 @@ public String pathWithQueryAndFragment() {
}

if (info.fragment().hasValue()) {
String fragmentValue = skipUriEncoding ? info.fragment().value() : info.fragment().rawValue();
String fragmentValue = decoded ? info.fragment().value() : info.fragment().rawValue();
path = path + '#' + fragmentValue;
}

Expand Down

0 comments on commit b10b661

Please sign in to comment.