diff --git a/ruma-client-api/src/r0/state/get_state_events_for_key.rs b/ruma-client-api/src/r0/state/get_state_events_for_key.rs index b4600da5..48ad8b77 100644 --- a/ruma-client-api/src/r0/state/get_state_events_for_key.rs +++ b/ruma-client-api/src/r0/state/get_state_events_for_key.rs @@ -142,17 +142,21 @@ impl ruma_api::IncomingRequest for IncomingRequest { } }; - let state_key = { - let decoded = - match percent_encoding::percent_decode(path_segments[7].as_bytes()).decode_utf8() { + let state_key = match path_segments.get(7) { + Some(segment) => { + let decoded = match percent_encoding::percent_decode(segment.as_bytes()) + .decode_utf8() + { Ok(val) => val, Err(err) => return Err(RequestDeserializationError::new(err, request).into()), }; - match String::try_from(&*decoded) { - Ok(val) => val, - Err(err) => return Err(RequestDeserializationError::new(err, request).into()), + match String::try_from(&*decoded) { + Ok(val) => val, + Err(err) => return Err(RequestDeserializationError::new(err, request).into()), + } } + None => "".into(), }; Ok(Self { room_id, event_type, state_key }) diff --git a/ruma-client-api/src/r0/state/send_state_event.rs b/ruma-client-api/src/r0/state/send_state_event.rs index 345833ee..292e6fc9 100644 --- a/ruma-client-api/src/r0/state/send_state_event.rs +++ b/ruma-client-api/src/r0/state/send_state_event.rs @@ -129,11 +129,15 @@ impl ruma_api::IncomingRequest for IncomingRequest { } }; - let state_key = - match percent_encoding::percent_decode(path_segments[7].as_bytes()).decode_utf8() { - Ok(val) => val.into_owned(), - Err(err) => return Err(RequestDeserializationError::new(err, request).into()), - }; + let state_key = match path_segments.get(7) { + Some(segment) => { + match percent_encoding::percent_decode(segment.as_bytes()).decode_utf8() { + Ok(val) => val.into_owned(), + Err(err) => return Err(RequestDeserializationError::new(err, request).into()), + } + } + None => "".into(), + }; let content = { let request_body: Box =