Skip to content

Commit bf33ec6

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Fix requesting non-ascii files
The issue was that we weren't percent-decoding the request before sending to the database.
1 parent c0718f5 commit bf33ec6

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/web/rustdoc.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
},
1010
Config, Metrics, Storage,
1111
};
12+
use iron::url::percent_encoding::percent_decode;
1213
use iron::{
1314
headers::{CacheControl, CacheDirective, Expires, HttpDate},
1415
modifiers::Redirect,
@@ -44,8 +45,6 @@ impl iron::Handler for RustLangRedirector {
4445
/// Handler called for `/:crate` and `/:crate/:version` URLs. Automatically redirects to the docs
4546
/// or crate details page based on whether the given crate version was successfully built.
4647
pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
47-
use iron::url::percent_encoding::percent_decode;
48-
4948
fn redirect_to_doc(
5049
req: &Request,
5150
name: &str,
@@ -331,14 +330,15 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
331330
path.push_str("index.html");
332331
req_path.push("index.html");
333332
}
333+
let mut path = ctry!(req, percent_decode(path.as_bytes()).decode_utf8());
334334

335335
// Attempt to load the file from the database
336336
let file = match File::from_path(&storage, &path, &config) {
337337
Ok(file) => file,
338338
Err(err) => {
339339
log::debug!("got error serving {}: {}", path, err);
340340
// If it fails, we try again with /index.html at the end
341-
path.push_str("/index.html");
341+
path.to_mut().push_str("/index.html");
342342
req_path.push("index.html");
343343

344344
return if ctry!(req, storage.exists(&path)) {
@@ -1573,6 +1573,21 @@ mod test {
15731573
})
15741574
}
15751575

1576+
#[test]
1577+
fn test_non_ascii() {
1578+
wrapper(|env| {
1579+
env.fake_release()
1580+
.name("const_unit_poc")
1581+
.version("1.0.0")
1582+
.rustdoc_file("const_unit_poc/units/constant.Ω.html")
1583+
.create()?;
1584+
assert_success(
1585+
"/const_unit_poc/1.0.0/const_unit_poc/units/constant.Ω.html",
1586+
env.frontend(),
1587+
)
1588+
})
1589+
}
1590+
15761591
#[test]
15771592
fn test_latest_version_keeps_query() {
15781593
wrapper(|env| {

0 commit comments

Comments
 (0)