Przeglądaj źródła

form_urlencoded: clean up clippy warnings

Dirkjan Ochtman 6 lat temu
rodzic
commit
0fb53a7595
1 zmienionych plików z 9 dodań i 2 usunięć
  1. 9 2
      form_urlencoded/src/lib.rs

+ 9 - 2
form_urlencoded/src/lib.rs

@@ -214,7 +214,14 @@ impl<'a, T: Target> Serializer<'a, T> {
     /// If that suffix is non-empty,
     /// its content is assumed to already be in `application/x-www-form-urlencoded` syntax.
     pub fn for_suffix(mut target: T, start_position: usize) -> Self {
-        &target.as_mut_string()[start_position..]; // Panic if out of bounds
+        if target.as_mut_string().len() < start_position {
+            panic!(
+                "invalid length {} for target of length {}",
+                start_position,
+                target.as_mut_string().len()
+            );
+        }
+
         Serializer {
             target: Some(target),
             start_position,
@@ -327,5 +334,5 @@ fn append_pair(
 }
 
 fn append_encoded(s: &str, string: &mut String, encoding: EncodingOverride) {
-    string.extend(byte_serialize(&query_encoding::encode(encoding, s.into())))
+    string.extend(byte_serialize(&query_encoding::encode(encoding, s)))
 }