|
1 | 1 | use crate::{ |
2 | 2 | db::PoolError, |
3 | 3 | storage::PathNotFoundError, |
4 | | - web::{cache::CachePolicy, releases::Search, AxumErrorPage}, |
| 4 | + web::{cache::CachePolicy, encode_url_path, releases::Search, AxumErrorPage}, |
5 | 5 | }; |
6 | 6 | use anyhow::anyhow; |
7 | 7 | use axum::{ |
@@ -107,7 +107,7 @@ impl IntoResponse for AxumNope { |
107 | 107 | web_error.into_response() |
108 | 108 | } |
109 | 109 | AxumNope::Redirect(target, cache_policy) => { |
110 | | - match super::axum_cached_redirect(&target, cache_policy) { |
| 110 | + match super::axum_cached_redirect(&encode_url_path(&target), cache_policy) { |
111 | 111 | Ok(response) => response.into_response(), |
112 | 112 | Err(err) => AxumNope::InternalError(err).into_response(), |
113 | 113 | } |
@@ -144,9 +144,20 @@ pub(crate) type AxumResult<T> = Result<T, AxumNope>; |
144 | 144 |
|
145 | 145 | #[cfg(test)] |
146 | 146 | mod tests { |
147 | | - use crate::test::wrapper; |
| 147 | + use super::{AxumNope, IntoResponse}; |
| 148 | + use crate::{test::wrapper, web::cache::CachePolicy}; |
148 | 149 | use kuchikiki::traits::TendrilSink; |
149 | 150 |
|
| 151 | + #[test] |
| 152 | + fn test_redirect_error_encodes_url_path() { |
| 153 | + let response = |
| 154 | + AxumNope::Redirect("/something>".into(), CachePolicy::ForeverInCdnAndBrowser) |
| 155 | + .into_response(); |
| 156 | + |
| 157 | + assert_eq!(response.status(), 302); |
| 158 | + assert_eq!(response.headers().get("Location").unwrap(), "/something%3E"); |
| 159 | + } |
| 160 | + |
150 | 161 | #[test] |
151 | 162 | fn check_404_page_content_crate() { |
152 | 163 | wrapper(|env| { |
|
0 commit comments