Skip to content

Commit 8aa81ab

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Redirect /proc-macro to /proc_macro
1 parent 8abe17a commit 8aa81ab

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/web/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,11 @@ mod test {
713713
assert_redirect(&format!("/{}", krate), &target, web)?;
714714
assert_redirect(&format!("/{}/", krate), &target, web)?;
715715
}
716+
let target = format!("https://doc.rust-lang.org/stable/proc_macro/");
717+
718+
// with or without slash
719+
assert_redirect("/proc-macro", &target, web)?;
720+
assert_redirect("/proc-macro/", &target, web)?;
716721
Ok(())
717722
})
718723
}

src/web/routes.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ pub(super) fn build_routes() -> Routes {
142142
super::rustdoc::RustLangRedirector::new(redirect),
143143
);
144144
}
145+
// redirect proc-macro to proc_macro
146+
routes.internal_page(
147+
"/proc-macro",
148+
super::rustdoc::RustLangRedirector::new("proc_macro"),
149+
);
145150

146151
routes
147152
}
@@ -320,10 +325,15 @@ impl Handler for BlockBlacklistedPrefixes {
320325
/// Automatically generate a Route ID from a pattern. Every non-alphanumeric character is replaced
321326
/// with `_`.
322327
fn calculate_id(pattern: &str) -> String {
323-
pattern
324-
.chars()
325-
.map(|c| if c.is_alphanumeric() { c } else { '_' })
326-
.collect()
328+
let calculate_char = |c: char| {
329+
if c.is_alphanumeric() || c == '-' {
330+
c
331+
} else {
332+
'_'
333+
}
334+
};
335+
336+
pattern.chars().map(calculate_char).collect()
327337
}
328338

329339
#[cfg(test)]

0 commit comments

Comments
 (0)