Procházet zdrojové kódy

Revert "Remove unnecessary bounds checking in a couple places."

This reverts commit d3dfbf3123258fe27649dc74f0dd07a14a5801b2.

Let’s not add `unsafe` code gratuitously.
Simon Sapin před 9 roky
rodič
revize
1919d103a9
1 změnil soubory, kde provedl 5 přidání a 7 odebrání
  1. 5 7
      src/form_urlencoded.rs

+ 5 - 7
src/form_urlencoded.rs

@@ -64,7 +64,7 @@ pub fn parse_with_encoding<'a>(input: &'a [u8],
         for sequence in input.split(|&b| b == b'&') {
             // No '+' in "_charset_" to replace with ' '.
             if sequence.starts_with(b"_charset_=") {
-                let value = unsafe { &sequence.get_unchecked(b"_charset_=".len()..) };
+                let value = &sequence[b"_charset_=".len()..];
                 // Skip replacing '+' with ' ' in value since no encoding label contains either:
                 // https://encoding.spec.whatwg.org/#names-and-labels
                 if let Some(e) = EncodingOverride::lookup(value) {
@@ -126,12 +126,10 @@ fn replace_plus(input: &[u8]) -> Cow<[u8]> {
         None => Cow::Borrowed(input),
         Some(first_position) => {
             let mut replaced = input.to_owned();
-            unsafe {
-                *replaced.get_unchecked_mut(first_position) = b' ';
-                for byte in replaced.get_unchecked_mut(first_position + 1..) {
-                    if *byte == b'+' {
-                        *byte = b' ';
-                    }
+            replaced[first_position] = b' ';
+            for byte in &mut replaced[first_position + 1..] {
+                if *byte == b'+' {
+                    *byte = b' ';
                 }
             }
             Cow::Owned(replaced)