Skip to content

Commit 73fc76e

Browse files
author
bors-servo
authored
Auto merge of #401 - servo:revert, r=SimonSapin
Revert "Remove unnecessary bounds checking in a couple places." This reverts commit d3dfbf3. Let’s not add `unsafe` code gratuitously. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/401) <!-- Reviewable:end -->
2 parents b57d49b + 1919d10 commit 73fc76e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/form_urlencoded.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn parse_with_encoding<'a>(input: &'a [u8],
6464
for sequence in input.split(|&b| b == b'&') {
6565
// No '+' in "_charset_" to replace with ' '.
6666
if sequence.starts_with(b"_charset_=") {
67-
let value = unsafe { &sequence.get_unchecked(b"_charset_=".len()..) };
67+
let value = &sequence[b"_charset_=".len()..];
6868
// Skip replacing '+' with ' ' in value since no encoding label contains either:
6969
// https://encoding.spec.whatwg.org/#names-and-labels
7070
if let Some(e) = EncodingOverride::lookup(value) {
@@ -126,12 +126,10 @@ fn replace_plus(input: &[u8]) -> Cow<[u8]> {
126126
None => Cow::Borrowed(input),
127127
Some(first_position) => {
128128
let mut replaced = input.to_owned();
129-
unsafe {
130-
*replaced.get_unchecked_mut(first_position) = b' ';
131-
for byte in replaced.get_unchecked_mut(first_position + 1..) {
132-
if *byte == b'+' {
133-
*byte = b' ';
134-
}
129+
replaced[first_position] = b' ';
130+
for byte in &mut replaced[first_position + 1..] {
131+
if *byte == b'+' {
132+
*byte = b' ';
135133
}
136134
}
137135
Cow::Owned(replaced)

0 commit comments

Comments
 (0)