diff --git a/src/redirect.rs b/src/redirect.rs index 00faf6e4c..eabaea37b 100644 --- a/src/redirect.rs +++ b/src/redirect.rs @@ -128,7 +128,7 @@ impl Policy { match self.inner { PolicyKind::Custom(ref custom) => custom(attempt), PolicyKind::Limit(max) => { - if attempt.previous.len() == max { + if attempt.previous.len() >= max { attempt.error(TooManyRedirects) } else { attempt.follow() @@ -277,6 +277,18 @@ fn test_redirect_policy_limit() { } } +#[test] +fn test_redirect_policy_limit_to_0() { + let policy = Policy::limited(0); + let next = Url::parse("http://x.y/z").unwrap(); + let previous = vec![Url::parse("http://a.b/c").unwrap()]; + + match policy.check(StatusCode::FOUND, &next, &previous) { + ActionKind::Error(err) if err.is::() => (), + other => panic!("unexpected {:?}", other), + } +} + #[test] fn test_redirect_policy_custom() { let policy = Policy::custom(|attempt| {