From ebd0d8fc77da699118a395f17f064043979a2977 Mon Sep 17 00:00:00 2001 From: Yuriy Tymchuk Date: Wed, 13 Nov 2024 11:39:59 +0100 Subject: [PATCH] Use URI to retrieve decoded path segments in ArmeriaServerRequest (#4162) --- .../sttp/tapir/server/armeria/ArmeriaServerRequest.scala | 8 ++------ .../scala/sttp/tapir/server/tests/ServerBasicTests.scala | 6 ++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaServerRequest.scala b/server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaServerRequest.scala index ec2190ebfa..bb95fd9e66 100644 --- a/server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaServerRequest.scala +++ b/server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaServerRequest.scala @@ -38,12 +38,8 @@ private[armeria] final case class ArmeriaServerRequest(ctx: ServiceRequestContex override def underlying: Any = ctx override val pathSegments: List[String] = { - // ctx.path() always starts with '/'. - if (ctx.path() == "/") { - Nil - } else { - ctx.path().substring(1).split("/").toList - } + val segments = uri.pathSegments.segments.map(_.v).filter(_.nonEmpty).toList + if (segments == List("")) Nil else segments // representing the root path as an empty list } override val queryParameters: QueryParams = { diff --git a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala index 544c8d4773..b457ca3e64 100644 --- a/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala +++ b/server/tests/src/main/scala/sttp/tapir/server/tests/ServerBasicTests.scala @@ -461,6 +461,12 @@ class ServerBasicTests[F[_], OPTIONS, ROUTE]( (backend, baseUri) => basicRequest.get(uri"$baseUri/api").send(backend).map(_.code shouldBe StatusCode.Ok) }, + testServer(in_path_paths_out_header_body, "Encoded path should be decoded") { case (i, paths) => + pureResult(Right((i, paths.last))) + }{ + (backend, baseUri) => + basicRequest.get(uri"$baseUri/api/15/and/MIN%2FMAX").send(backend).map(_.body shouldBe Right("MIN/MAX")) + }, testServer(in_single_path, "single path should match single/ path")((_: Unit) => pureResult(Either.right[Unit, Unit](()))) { (backend, baseUri) => basicRequest.get(uri"$baseUri/api/").send(backend).map(_.code shouldBe StatusCode.Ok)