Skip to content

Commit 65f4580

Browse files
committed
using get instead of directly accessing index for channelId string
1 parent 687f3db commit 65f4580

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

primitives/src/channel.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ where
3737
}
3838

3939
fn validate_channel_id(s: &str) -> Result<&str, FromHexError> {
40-
if s.is_empty() || s.len() != 66 || &s[0..2] != "0x" {
41-
Err(FromHexError::InvalidStringLength)
42-
} else {
43-
Ok(&s[2..])
40+
match (s.get(0..2), s.get(2..)) {
41+
(Some(prefix), Some(hex)) => if s.len() != 66 || prefix != "0x" {
42+
Err(FromHexError::InvalidStringLength)
43+
} else {
44+
Ok(hex)
45+
},
46+
_ => Err(FromHexError::InvalidStringLength)
4447
}
4548
}
4649

0 commit comments

Comments
 (0)