Unverified Commit c36afd61 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Fix StackOverflow in SdkBody Debug (#343)

* Fix StackOverflow in SdkBody Debug

An incorrect debug implementation lead to infinite recursion when printing `SdkBody` with the debug formatter

* CR Feedback
parent d6e82f5f
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -44,7 +44,9 @@ enum Inner {
impl Debug for Inner {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match &self {
            i @ Inner::Once(_) | i @ Inner::Streaming(_) | i @ Inner::Taken => i.fmt(f),
            Inner::Once(once) => f.debug_tuple("Once").field(once).finish(),
            Inner::Streaming(streaming) => f.debug_tuple("Streaming").field(streaming).finish(),
            Inner::Taken => f.debug_tuple("Taken").finish(),
            Inner::Dyn(_) => write!(f, "BoxBody"),
        }
    }
@@ -166,7 +168,7 @@ impl http_body::Body for SdkBody {

#[cfg(test)]
mod test {
    use crate::body::SdkBody;
    use crate::body::{BoxBody, SdkBody};
    use http_body::Body;
    use std::pin::Pin;

@@ -200,4 +202,27 @@ mod test {
        let data = body.data().await;
        assert!(data.is_none());
    }

    #[test]
    fn sdkbody_debug_once() {
        let body = SdkBody::from("123");
        // actually don't really care what the debug impl is, just that it doesn't crash
        let _ = format!("{:?}", body);
    }

    #[test]
    fn sdkbody_debug_dyn() {
        let hyper_body = hyper::Body::channel().1;
        let body = SdkBody::from_dyn(BoxBody::new(hyper_body.map_err(|e| e.into())));
        // actually don't really care what the debug impl is, just that it doesn't crash
        let _ = format!("{:?}", body);
    }

    #[test]
    fn sdkbody_debug_hyper() {
        let hyper_body = hyper::Body::channel().1;
        let body = SdkBody::from(hyper_body);
        // actually don't really care what the debug impl is, just that it doesn't crash
        let _ = format!("{:?}", body);
    }
}