Don't panic when array type is used for path segment (#3039)

This commit is contained in:
Jonas Platte 2024-11-19 21:57:30 +01:00 committed by GitHub
parent 7e59625778
commit 9517decf2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 3 deletions

View file

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased # Unreleased
- **fixed:** Skip SSE incompatible chars of `serde_json::RawValue` in `Event::json_data` ([#2992]) - **fixed:** Skip SSE incompatible chars of `serde_json::RawValue` in `Event::json_data` ([#2992])
- **fixed:** Don't panic when array type is used for path segment ([#3039])
- **breaking:** Move `Host` extractor to `axum-extra` ([#2956]) - **breaking:** Move `Host` extractor to `axum-extra` ([#2956])
- **added:** Add `method_not_allowed_fallback` to set a fallback when a path matches but there is no handler for the given HTTP method ([#2903]) - **added:** Add `method_not_allowed_fallback` to set a fallback when a path matches but there is no handler for the given HTTP method ([#2903])
- **added:** Add `NoContent` as a self-described shortcut for `StatusCode::NO_CONTENT` ([#2978]) - **added:** Add `NoContent` as a self-described shortcut for `StatusCode::NO_CONTENT` ([#2978])
@ -32,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2978]: https://github.com/tokio-rs/axum/pull/2978 [#2978]: https://github.com/tokio-rs/axum/pull/2978
[#2992]: https://github.com/tokio-rs/axum/pull/2992 [#2992]: https://github.com/tokio-rs/axum/pull/2992
[#2720]: https://github.com/tokio-rs/axum/pull/2720 [#2720]: https://github.com/tokio-rs/axum/pull/2720
[#3039]: https://github.com/tokio-rs/axum/pull/3039
# 0.8.0 # 0.8.0

View file

@ -454,9 +454,11 @@ impl<'de> Deserializer<'de> for ValueDeserializer<'de> {
Some(KeyOrIdx::Idx { idx: _, key }) => { Some(KeyOrIdx::Idx { idx: _, key }) => {
return seed.deserialize(KeyDeserializer { key }).map(Some); return seed.deserialize(KeyDeserializer { key }).map(Some);
} }
// `KeyOrIdx::Key` is only used when deserializing maps so `deserialize_seq` Some(KeyOrIdx::Key(_)) => {
// wouldn't be called for that return Err(PathDeserializationError::custom(
Some(KeyOrIdx::Key(_)) => unreachable!(), "array types are not supported",
));
}
None => {} None => {}
}; };

View file

@ -973,4 +973,25 @@ mod tests {
r#"Invalid URL: Cannot parse `res` with value `456456-123-456456`: UUID parsing failed: invalid group count: expected 5, found 3"# r#"Invalid URL: Cannot parse `res` with value `456456-123-456456`: UUID parsing failed: invalid group count: expected 5, found 3"#
); );
} }
#[crate::test]
async fn regression_3038() {
#[derive(Deserialize)]
#[allow(dead_code)]
struct MoreChars {
first_two: [char; 2],
second_two: [char; 2],
crate_name: String,
}
let app = Router::new().route(
"/{first_two}/{second_two}/{crate_name}",
get(|Path(_): Path<MoreChars>| async move {}),
);
let client = TestClient::new(app);
let res = client.get("/te/st/_thing").await;
let body = res.text().await;
assert_eq!(body, r#"Invalid URL: array types are not supported"#);
}
} }