Skip to content

Commit

Permalink
Decode path. Fix 1
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed Oct 26, 2023
1 parent bba4aa7 commit be4c833
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
6 changes: 4 additions & 2 deletions http/http/src/main/java/io/helidon/http/PathMatchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.regex.Pattern;

import io.helidon.common.parameters.Parameters;
import io.helidon.common.uri.UriEncoding;
import io.helidon.common.uri.UriPath;

/**
Expand Down Expand Up @@ -276,8 +277,9 @@ static final class ExactPathMatcher implements PathMatcher {
private final String pathWithTrailingSlash;

ExactPathMatcher(String path) {
this.path = path;
this.pathWithTrailingSlash = path + "/";
// We work with decoded URIs
this.path = UriEncoding.decodeUri(path);
this.pathWithTrailingSlash = this.path + "/";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.microprofile.server;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import java.util.HashSet;
import java.util.Set;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.core.Application;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

class JaxRsApplicationPathTest {

private static Server server;
private static Client client;
private static int port;

@BeforeAll
static void beforeAll() {
server = Server.builder().addApplication(MyApplication.class).build();
server.start();
port = server.port();
client = ClientBuilder.newClient();
}

@AfterAll
static void afterAll() {
server.stop();
client.close();
}

@Test
void okTest() {
String getResponse = client.target("http://localhost:" + port)
.path("/ApplicationPath!/Resource").request().get(String.class);
assertThat(getResponse, is("ok"));
}

@Test
void nokTest() {
int status = client.target("http://localhost:" + port)
.path("/Resource").request().get().getStatus();
assertThat(status, is(404));
}

@ApplicationPath("/ApplicationPath%21")
static class MyApplication extends Application {

@Override
public java.util.Set<java.lang.Class<?>> getClasses() {
Set<Class<?>> resources = new HashSet<Class<?>>();
resources.add(TestResource.class);
return resources;
}
}

@Path("/Resource")
public static class TestResource {

@GET
public String param() {
return "ok";
}

}
}

0 comments on commit be4c833

Please sign in to comment.