updated with new urldecode algorithm
@@ -369,29 +369,37 @@ fn from_hex_digit(digit: u8) -> Option<u8> {
fn urldecode(input: String) -> Vec<u8> {
let mut out = Vec::new();
let mut bytes = input.as_bytes().iter().copied();
- while let Some(b) = bytes.next() {
+ while let Some(mut b) = bytes.next() {
+ loop {
if b == b'%' {
if let Some(h) = bytes.next() {
+ if let Some(hv) = from_hex_digit(h) {
if let Some(l) = bytes.next() {
- match from_hex_digit(h).and_then(|hv| from_hex_digit(l).map(|lv| (hv, lv))) {
- None => {
+ if let Some(lv) = from_hex_digit(l) {
+ out.push(hv * 16 + lv);
+ break;
+ } else {
out.push(b);
out.push(h);
- out.push(l);
- }
- Some((hv, lv)) => {
- out.push(hv * 16 + lv);
- }
+ b = l;
}
} else {
out.push(b);
out.push(h);
+ break;
}
} else {
out.push(b);
+ b = h;
}
} else {
out.push(b);
+ break;
+ }
+ } else {
+ out.push(b);
+ break;
+ }
}
}
out
