Skip to content

rustdoc: fix buggy JS check for absolute URL #106437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ function loadCss(cssUrl) {
onEachLazy(code.getElementsByTagName("a"), elem => {
const href = elem.getAttribute("href");

if (href && href.indexOf("http") !== 0) {
if (href && !/^(?:[a-z+]+:)?\/\//.test(href)) {
elem.setAttribute("href", window.rootPath + href);
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc-gui/implementors.goml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ goto: "file://" + |DOC_PATH| + "/lib2/trait.TraitToReexport.html"
assert-count: ("#implementors-list .impl", 1)
goto: "file://" + |DOC_PATH| + "/implementors/trait.TraitToReexport.html"
assert-count: ("#implementors-list .impl", 1)

// Now check that the link is properly rewritten for a crate called `http`.
// An older version of rustdoc had a buggy check for absolute links.
goto: "file://" + |DOC_PATH| + "/http/trait.HttpTrait.html"
assert-count: ("#implementors-list .impl", 1)
assert-attribute: ("#implementors-list .impl a.trait", {"href": "../http/trait.HttpTrait.html"})
2 changes: 2 additions & 0 deletions src/test/rustdoc-gui/search-filter.goml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ click: "#crate-search"
press-key: "ArrowDown"
press-key: "ArrowDown"
press-key: "ArrowDown"
press-key: "ArrowDown"
press-key: "Enter"
// Waiting for the search results to appear...
wait-for: "#search-tabs"
Expand All @@ -39,6 +40,7 @@ click: "#crate-search"
press-key: "ArrowUp"
press-key: "ArrowUp"
press-key: "ArrowUp"
press-key: "ArrowUp"
press-key: "Enter"
// Waiting for the search results to appear...
wait-for: "#search-tabs"
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/sidebar-source-code.goml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
// Only "another_folder" should be "open" in "lib2".
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
// All other trees should be collapsed.
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 7)
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 8)

// We now switch to mobile mode.
size: (600, 600)
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/source-code-page.goml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ assert: ".source-sidebar-expanded"

// We check that the first entry of the sidebar is collapsed
assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
assert-text: ("#source-sidebar details:first-of-type > summary", "huge_logo")
assert-text: ("#source-sidebar details:first-of-type > summary", "http")
// We now click on it.
click: "#source-sidebar details:first-of-type > summary"
assert-property: ("#source-sidebar details:first-of-type", {"open": "true"})
Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc-gui/src/lib2/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
# It is not intended for manual editing.
version = 3

[[package]]
name = "http"
version = "0.1.0"

[[package]]
name = "implementors"
version = "0.1.0"
dependencies = [
"http",
]

[[package]]
name = "lib2"
version = "0.1.0"
dependencies = [
"http",
"implementors",
]
1 change: 1 addition & 0 deletions src/test/rustdoc-gui/src/lib2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ path = "lib.rs"

[dependencies]
implementors = { path = "./implementors" }
http = { path = "./http" }
7 changes: 7 additions & 0 deletions src/test/rustdoc-gui/src/lib2/http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "http"
version = "0.1.0"
edition = "2018"

[lib]
path = "lib.rs"
1 change: 1 addition & 0 deletions src/test/rustdoc-gui/src/lib2/http/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub trait HttpTrait {}
3 changes: 3 additions & 0 deletions src/test/rustdoc-gui/src/lib2/implementors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ edition = "2018"

[lib]
path = "lib.rs"

[dependencies]
http = { path = "../http/" }
2 changes: 2 additions & 0 deletions src/test/rustdoc-gui/src/lib2/implementors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ impl Whatever for Struct {
type Foo = u8;
}

impl http::HttpTrait for Struct {}

mod traits {
pub trait TraitToReexport {
fn method() {}
Expand Down