poem
poem copied to clipboard
Regex routing: byte index 14 is out of bounds of `/api/clients`
Expected Behavior
Route successfully
Actual Behavior
Router panics with byte index 14 is out of bounds of /api/clients
Steps to Reproduce the Problem
- Create a route and then
.nest_no_strip("/<(api|oauth)>", service)
- Send a request for example to
/api/clients
I'm using an OpenApi
service for service
. I have other stuff on route /
and that's why I wanted to do this.
Specifications
- Version: 1.3.52
- Platform: Arch Linux
I can't reproduce this issue:
let app = Route::new().nest_no_strip(
"/<(api|oauth)>",
make_sync(|req| req.uri().path().to_string()),
);
let resp = app
.get_response(
Request::builder()
.uri(Uri::from_static("/api/clients"))
.finish(),
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(
resp.into_body().into_string().await.unwrap(),
"/api/clients"
);
Seems like I provided too little detail. I managed to reproduce with this:
use poem::{
http::{StatusCode, Uri},
Endpoint, Request, Route,
};
use poem_openapi::{payload::Json, OpenApi, OpenApiService};
struct ClientApi;
#[OpenApi(prefix_path = "/api/clients")]
impl ClientApi {
#[oai(path = "/", method = "get")]
async fn list(&self) -> Json<String> {
Json("/api/clients".to_string())
}
}
#[tokio::main]
async fn main() {
let service = OpenApiService::new(ClientApi, "Clients", env!("CARGO_PKG_VERSION"));
let app = Route::new().nest_no_strip("/<(api|oauth)>", service);
let resp = app
.get_response(
Request::builder()
.uri(Uri::from_static("/api/clients"))
.finish(),
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(
resp.into_body().into_string().await.unwrap(),
"/api/clients"
);
}
regex on nested paths are not currently supported, you can do it like below:
let app = Route::new().nest_no_strip("/api", service)
.nest_no_strip("/api", service)
.nest_no_strip("/oauth", service);
Sorry, I'm unsure how to go about this, since the OpenAPI service doesn't implement either Copy
or Clone
.