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

Fixes a few problems handling character encodings in URIs #8327

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -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
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"));
}
}
Loading