From bba4aa7a9389a19ac844680a87a4bdb73eea4b13 Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Tue, 24 Oct 2023 13:27:35 +0200 Subject: [PATCH] Fix matrix TCKs Signed-off-by: Jorge Bescos Gascon --- .../uri/src/main/java/io/helidon/common/uri/UriPath.java | 6 ++++++ .../src/main/java/io/helidon/common/uri/UriPathMatrix.java | 5 +++++ .../main/java/io/helidon/common/uri/UriPathNoParam.java | 5 +++++ .../src/test/java/io/helidon/common/uri/UriPathTest.java | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/common/uri/src/main/java/io/helidon/common/uri/UriPath.java b/common/uri/src/main/java/io/helidon/common/uri/UriPath.java index 08a5f5493dc..0aa19f65161 100644 --- a/common/uri/src/main/java/io/helidon/common/uri/UriPath.java +++ b/common/uri/src/main/java/io/helidon/common/uri/UriPath.java @@ -34,6 +34,12 @@ public interface UriPath { * @return a new path representing the new relative path */ static UriPath createRelative(UriPath uriPath, String relativePath) { + if (uriPath instanceof UriPathMatrix) { + String rawPath = uriPath.rawPath(); + int idx = rawPath.indexOf(relativePath); + rawPath = rawPath.substring(idx); + return new UriPathMatrix(rawPath, relativePath); + } return new UriPathNoParam(uriPath.absolute(), relativePath); } diff --git a/common/uri/src/main/java/io/helidon/common/uri/UriPathMatrix.java b/common/uri/src/main/java/io/helidon/common/uri/UriPathMatrix.java index c19e0eb7c11..e0f18761e09 100644 --- a/common/uri/src/main/java/io/helidon/common/uri/UriPathMatrix.java +++ b/common/uri/src/main/java/io/helidon/common/uri/UriPathMatrix.java @@ -30,6 +30,11 @@ class UriPathMatrix extends UriPathNoParam { this.rawPath = rawPath; } + UriPathMatrix(String rawPath, String noParamPath, UriPath absolute) { + super(noParamPath, absolute); + this.rawPath = rawPath; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/common/uri/src/main/java/io/helidon/common/uri/UriPathNoParam.java b/common/uri/src/main/java/io/helidon/common/uri/UriPathNoParam.java index 0d4b2d5a2ae..2234c4b2cc7 100644 --- a/common/uri/src/main/java/io/helidon/common/uri/UriPathNoParam.java +++ b/common/uri/src/main/java/io/helidon/common/uri/UriPathNoParam.java @@ -35,6 +35,11 @@ class UriPathNoParam implements UriPath { this.absolute = this; } + UriPathNoParam(String rawPath, UriPath absolute) { + this.rawPath = rawPath; + this.absolute = absolute; + } + UriPathNoParam(UriPath absolute, String relativePath) { this.rawPath = relativePath; this.decodedPath = relativePath; diff --git a/common/uri/src/test/java/io/helidon/common/uri/UriPathTest.java b/common/uri/src/test/java/io/helidon/common/uri/UriPathTest.java index f94f70f1193..8f23d3126d6 100644 --- a/common/uri/src/test/java/io/helidon/common/uri/UriPathTest.java +++ b/common/uri/src/test/java/io/helidon/common/uri/UriPathTest.java @@ -51,4 +51,11 @@ void testDoubleSlash(String rawPath) { UriPath path = UriPath.create(rawPath); assertThat(path.path(), is("/foo/bar")); } + + @Test + void testMatrix() { + UriPath raw = UriPath.create("/jaxrs_spec/resource/entitymatrix;param=ASDFGHJKLQWERTYUIOPPPPPPP"); + UriPath relative = (UriPathMatrix) UriPath.createRelative(raw, "/resource/entitymatrix"); + assertThat(relative.rawPath(), is("/resource/entitymatrix;param=ASDFGHJKLQWERTYUIOPPPPPPP")); + } }