Skip to content

Commit

Permalink
Fixes a few problems handling character encodings in URIs (helidon-io…
Browse files Browse the repository at this point in the history
…#8327)

* Fixes problems converting a ClientUri to a URI. Improved test.

Signed-off-by: Santiago Pericasgeertsen <[email protected]>

* Drops skip encoding setting in connector after fixing handling of + in ClientUri query string.

Signed-off-by: Santiago Pericasgeertsen <[email protected]>

* Trying using forkCount set to 1.

Signed-off-by: Santiago Pericasgeertsen <[email protected]>

---------

Signed-off-by: Santiago Pericasgeertsen <[email protected]>
  • Loading branch information
spericas authored Feb 5, 2024
1 parent 4a5623c commit 1cf9272
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 35 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 @@ -151,7 +151,6 @@ private HttpClientRequest mapRequest(ClientRequest request) {
HttpClientRequest httpRequest = webClient
.method(Method.create(request.getMethod()))
.proxy(requestProxy)
.skipUriEncoding(true) // already encoded by Jersey
.uri(uri);

// map request headers
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
30 changes: 6 additions & 24 deletions microprofile/telemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>helidon-microprofile-project</artifactId>
Expand Down Expand Up @@ -137,28 +137,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<configuration>
<excludes>
<exclude>**/WithSpanWithExplicitAppTest.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<!-- Run in a separate execution so other tests don't have the Application bean in play. -->
<id>test-with-explicit-app</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/WithSpanWithExplicitAppTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
</configuration>
</plugin>
</plugins>
</build>
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 All @@ -18,6 +18,7 @@

import java.net.URI;

import io.helidon.common.uri.UriEncoding;
import io.helidon.common.uri.UriFragment;
import io.helidon.common.uri.UriInfo;
import io.helidon.common.uri.UriPath;
Expand Down Expand Up @@ -193,8 +194,11 @@ public ClientUri resolve(URI uri) {

uriBuilder.path(resolvePath(uriBuilder.path().path(), uri.getPath()));

if (uri.getQuery() != null) {
query.fromQueryString(uri.getQuery());
String queryString = uri.getQuery();
if (queryString != null) {
// class URI does not decode +'s, so we do it here
query.fromQueryString(queryString.indexOf('+') >= 0 ? UriEncoding.decodeUri(queryString)
: queryString);
}

if (uri.getRawFragment() != null) {
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 All @@ -20,7 +20,6 @@

import io.helidon.common.uri.UriPath;
import io.helidon.common.uri.UriQueryWriteable;

import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -105,4 +104,17 @@ void testResolveAll() {
assertThat(helper.port(), is(80));
assertThat(helper.scheme(), is("https"));
}

/**
* Verifies that "+" is interpreted as a space character the query strings.
* Note that the {@link URI} class does not appear to handle this correctly.
*/
@Test
void testResolveQuery() {
URI uri = URI.create("http://localhost:8080/greet?filter=a+b+c");
ClientUri clientUri = ClientUri.create();
clientUri.resolve(uri);
assertThat(clientUri.query().get("filter"), is("a b c"));
assertThat(clientUri.query().getRaw("filter"), is("a%20b%20c"));
}
}

0 comments on commit 1cf9272

Please sign in to comment.