fix(deser): fix indexing into `str` bug

[str](https://doc.rust-lang.org/std/primitive.str.html) consist of unicode characters which can be between 1-4 bytes
long and indexing assuming that all are 1 byte may panic
This commit is contained in:
Niklas Adolfsson 2019-02-07 17:32:07 +01:00
parent d9226f795b
commit 7a6ade2937
No known key found for this signature in database
GPG Key ID: A5C9609E830D742A
1 changed files with 1 additions and 1 deletions

View File

@ -81,7 +81,7 @@ pub fn deserialize_check_len<'de, D>(deserializer: D, len: ExpectedLen) -> Resul
}
fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E> {
if v.len() < 2 || &v[0..2] != "0x" {
if v.len() < 2 || !v.starts_with("0x") {
return Err(E::custom("prefix is missing"))
}