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

Add UriTemplate API to preserve raw path component #11477

Open
wants to merge 3 commits into
base: 4.8.x
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions http/src/main/java/io/micronaut/http/uri/UriTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ public int getRawSegmentLength() {
.reduce(Integer::sum)
.orElse(0);
}
/**
* Gets the raw unencoded path component from a URI.
*
* @param uri The URI string
* @return The raw path component, preserving encoding of special characters
* @since 4.8.0
*/
ChaimaaeROUAI marked this conversation as resolved.
Show resolved Hide resolved
public static String getRawPathComponent(String uri) {
int queryIndex = uri.indexOf('?');
String pathOnly = queryIndex >= 0 ? uri.substring(0, queryIndex) : uri;
int lastSlash = pathOnly.lastIndexOf('/');
return lastSlash >= 0 ? pathOnly.substring(lastSlash + 1) : pathOnly;
}

/**
* Nests another URI template with this template.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.micronaut.http.uri;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class UriTemplateRawPathTest {
@Test
void testGetRawPathComponent() {
String uri = "/test/1.0/024-02-07T00:30:48.014+00:00";
assertEquals("024-02-07T00:30:48.014+00:00", UriTemplate.getRawPathComponent(uri));
}

@Test
void testGetRawPathComponentWithQuery() {
String uri = "/test/1.0/024-02-07T00:30:48.014+00:00?param=value";
assertEquals("024-02-07T00:30:48.014+00:00", UriTemplate.getRawPathComponent(uri));
}
}
Loading