Remove a panic in normalize middleware

This commit is contained in:
Maciej Hirsz 2020-10-29 18:16:33 +01:00 committed by Yuki Okushi
parent 32d59ca904
commit 4f5b45317c
2 changed files with 5 additions and 2 deletions

View File

@ -30,6 +30,9 @@
* Re-export bytes::Buf{Mut} in web module. [#1750] * Re-export bytes::Buf{Mut} in web module. [#1750]
* Upgrade `pin-project` to `1.0`. * Upgrade `pin-project` to `1.0`.
### Fixed
* Removed an occasional `unwrap` on `None` panic in `NormalizePathNormalization`.
[#1723]: https://github.com/actix/actix-web/pull/1723 [#1723]: https://github.com/actix/actix-web/pull/1723
[#1743]: https://github.com/actix/actix-web/pull/1743 [#1743]: https://github.com/actix/actix-web/pull/1743
[#1748]: https://github.com/actix/actix-web/pull/1748 [#1748]: https://github.com/actix/actix-web/pull/1748

View File

@ -137,9 +137,9 @@ where
// so the change can not be deduced from the length comparison // so the change can not be deduced from the length comparison
if path != original_path { if path != original_path {
let mut parts = head.uri.clone().into_parts(); let mut parts = head.uri.clone().into_parts();
let pq = parts.path_and_query.as_ref().unwrap(); let query = parts.path_and_query.as_ref().and_then(|pq| pq.query());
let path = if let Some(q) = pq.query() { let path = if let Some(q) = query {
Bytes::from(format!("{}?{}", path, q)) Bytes::from(format!("{}?{}", path, q))
} else { } else {
Bytes::copy_from_slice(path.as_bytes()) Bytes::copy_from_slice(path.as_bytes())