Skip to content

Commit 7885ce5

Browse files
committed
Align small_url_encode and Escape
1 parent 14824c5 commit 7885ce5

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/librustdoc/html/escape.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,17 @@ impl<'a> fmt::Display for Escape<'a> {
1717
let pile_o_bits = s;
1818
let mut last = 0;
1919
for (i, ch) in s.bytes().enumerate() {
20-
match ch as char {
21-
'<' | '>' | '&' | '\'' | '"' => {
22-
fmt.write_str(&pile_o_bits[last..i])?;
23-
let s = match ch as char {
24-
'>' => "&gt;",
25-
'<' => "&lt;",
26-
'&' => "&amp;",
27-
'\'' => "&#39;",
28-
'"' => "&quot;",
29-
_ => unreachable!(),
30-
};
31-
fmt.write_str(s)?;
32-
last = i + 1;
33-
}
34-
_ => {}
35-
}
20+
let s = match ch as char {
21+
'>' => "&gt;",
22+
'<' => "&lt;",
23+
'&' => "&amp;",
24+
'\'' => "&#39;",
25+
'"' => "&quot;",
26+
_ => continue,
27+
};
28+
fmt.write_str(&pile_o_bits[last..i])?;
29+
fmt.write_str(s)?;
30+
last = i + 1;
3631
}
3732

3833
if last < s.len() {

src/librustdoc/html/render/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4267,8 +4267,8 @@ fn get_methods(
42674267
fn small_url_encode(s: String) -> String {
42684268
let mut st = String::new();
42694269
let mut last_match = 0;
4270-
for (idx, c) in s.char_indices() {
4271-
let escaped = match c {
4270+
for (idx, c) in s.bytes().enumerate() {
4271+
let escaped = match c as char {
42724272
'<' => "%3C",
42734273
'>' => "%3E",
42744274
' ' => "%20",
@@ -4286,7 +4286,7 @@ fn small_url_encode(s: String) -> String {
42864286

42874287
st += &s[last_match..idx];
42884288
st += escaped;
4289-
last_match = idx + c.len_utf8();
4289+
last_match = idx + 1;
42904290
}
42914291

42924292
if last_match != 0 {

0 commit comments

Comments
 (0)