Skip to content

Commit 49111ec

Browse files
committed
rustdoc: fix buggy JS check for absolute URL
The old code did the wrong thing when faced with a crate named "http".
1 parent ab10908 commit 49111ec

File tree

11 files changed

+33
-3
lines changed

11 files changed

+33
-3
lines changed

src/librustdoc/html/static/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ function loadCss(cssUrl) {
563563
onEachLazy(code.getElementsByTagName("a"), elem => {
564564
const href = elem.getAttribute("href");
565565

566-
if (href && href.indexOf("http") !== 0) {
566+
if (href && !/^(?:[a-z+]+:)?\/\//.test(href)) {
567567
elem.setAttribute("href", window.rootPath + href);
568568
}
569569
});

src/test/rustdoc-gui/implementors.goml

+6
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ goto: "file://" + |DOC_PATH| + "/lib2/trait.TraitToReexport.html"
3333
assert-count: ("#implementors-list .impl", 1)
3434
goto: "file://" + |DOC_PATH| + "/implementors/trait.TraitToReexport.html"
3535
assert-count: ("#implementors-list .impl", 1)
36+
37+
// Now check that the link is properly rewritten for a crate called `http`.
38+
// An older version of rustdoc had a buggy check for absolute links.
39+
goto: "file://" + |DOC_PATH| + "/http/trait.HttpTrait.html"
40+
assert-count: ("#implementors-list .impl", 1)
41+
assert-attribute: ("#implementors-list .impl a.trait", {"href": "../http/trait.HttpTrait.html"})

src/test/rustdoc-gui/search-filter.goml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ click: "#crate-search"
1515
press-key: "ArrowDown"
1616
press-key: "ArrowDown"
1717
press-key: "ArrowDown"
18+
press-key: "ArrowDown"
1819
press-key: "Enter"
1920
// Waiting for the search results to appear...
2021
wait-for: "#search-tabs"
@@ -39,6 +40,7 @@ click: "#crate-search"
3940
press-key: "ArrowUp"
4041
press-key: "ArrowUp"
4142
press-key: "ArrowUp"
43+
press-key: "ArrowUp"
4244
press-key: "Enter"
4345
// Waiting for the search results to appear...
4446
wait-for: "#search-tabs"

src/test/rustdoc-gui/sidebar-source-code.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
7373
// Only "another_folder" should be "open" in "lib2".
7474
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
7575
// All other trees should be collapsed.
76-
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 7)
76+
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 8)
7777

7878
// We now switch to mobile mode.
7979
size: (600, 600)

src/test/rustdoc-gui/source-code-page.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ assert: ".source-sidebar-expanded"
102102

103103
// We check that the first entry of the sidebar is collapsed
104104
assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
105-
assert-text: ("#source-sidebar details:first-of-type > summary", "huge_logo")
105+
assert-text: ("#source-sidebar details:first-of-type > summary", "http")
106106
// We now click on it.
107107
click: "#source-sidebar details:first-of-type > summary"
108108
assert-property: ("#source-sidebar details:first-of-type", {"open": "true"})

src/test/rustdoc-gui/src/lib2/Cargo.lock

+8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
# It is not intended for manual editing.
33
version = 3
44

5+
[[package]]
6+
name = "http"
7+
version = "0.1.0"
8+
59
[[package]]
610
name = "implementors"
711
version = "0.1.0"
12+
dependencies = [
13+
"http",
14+
]
815

916
[[package]]
1017
name = "lib2"
1118
version = "0.1.0"
1219
dependencies = [
20+
"http",
1321
"implementors",
1422
]

src/test/rustdoc-gui/src/lib2/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ path = "lib.rs"
88

99
[dependencies]
1010
implementors = { path = "./implementors" }
11+
http = { path = "./http" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "http"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[lib]
7+
path = "lib.rs"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub trait HttpTrait {}

src/test/rustdoc-gui/src/lib2/implementors/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ edition = "2018"
55

66
[lib]
77
path = "lib.rs"
8+
9+
[dependencies]
10+
http = { path = "../http/" }

src/test/rustdoc-gui/src/lib2/implementors/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ impl Whatever for Struct {
1010
type Foo = u8;
1111
}
1212

13+
impl http::HttpTrait for Struct {}
14+
1315
mod traits {
1416
pub trait TraitToReexport {
1517
fn method() {}

0 commit comments

Comments
 (0)