Percent-encode a string for safe use in URL path segments. RFC 3986 §3.3: pchar = unreserved / pct-encoded / sub-delims / ":" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" Must encode: `/`, `?`, `#`, space, and other non-pchar characters.
(input: &str)
| 582 | /// |
| 583 | /// Must encode: `/`, `?`, `#`, space, and other non-pchar characters. |
| 584 | fn percent_encode_path_segment(input: &str) -> String { |
| 585 | let mut encoded = String::with_capacity(input.len()); |
| 586 | for byte in input.bytes() { |
| 587 | match byte { |
| 588 | // unreserved + sub-delims + ":" + "@" |
| 589 | b'A'..=b'Z' |
| 590 | | b'a'..=b'z' |
| 591 | | b'0'..=b'9' |
| 592 | | b'-' |
| 593 | | b'.' |
| 594 | | b'_' |
| 595 | | b'~' |
| 596 | | b'!' |
| 597 | | b'$' |
| 598 | | b'&' |
| 599 | | b'\'' |
| 600 | | b'(' |
| 601 | | b')' |
| 602 | | b'*' |
| 603 | | b'+' |
| 604 | | b',' |
| 605 | | b';' |
| 606 | | b'=' |
| 607 | | b':' |
| 608 | | b'@' => { |
| 609 | encoded.push(byte as char); |
| 610 | } |
| 611 | _ => { |
| 612 | use fmt::Write; |
| 613 | let _ = write!(encoded, "%{byte:02X}"); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | encoded |
| 618 | } |
| 619 | |
| 620 | /// Percent-decode a URL-encoded string. |
| 621 | fn percent_decode(input: &str) -> String { |
no test coverage detected