From 1b19687d253364ccabc4dab43a9f29a2f6cfe1a8 Mon Sep 17 00:00:00 2001 From: Lucas Sunsi Abreu Date: Mon, 23 Sep 2024 15:34:01 -0300 Subject: [PATCH] fix: unicode on exactly index 7 should not panic --- src/de.rs | 2 +- src/lib.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/de.rs b/src/de.rs index fd7e84e..72aa340 100644 --- a/src/de.rs +++ b/src/de.rs @@ -25,7 +25,7 @@ impl<'a, T: DeserializeParams<'a>> Uri<'a, bitcoin::address::NetworkUnchecked, T return Err(Error::Uri(UriError(UriErrorInner::TooShort))); } - if !string[..SCHEME.len()].eq_ignore_ascii_case(SCHEME) { + if !string.get(..SCHEME.len()).is_some_and(|s| s.eq_ignore_ascii_case(SCHEME)) { return Err(Error::Uri(UriError(UriErrorInner::InvalidScheme))); } diff --git a/src/lib.rs b/src/lib.rs index b149115..73376c6 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -427,4 +427,11 @@ mod tests { assert!(uri.label.is_none()); assert!(uri.message.is_none()); } + + #[test] + fn bad_unicode_scheme() { + let input = "bitcoinö:1andreas3batLhQa2FawWjeyjCqyBzypd"; + let uri = input.parse::>(); + assert!(uri.is_err()); + } }