Skip to content

Search box on nested 404 page abc/123 goes to 404 abc/std/index.html?... #54952

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

Closed
huonw opened this issue Oct 10, 2018 · 6 comments
Closed

Search box on nested 404 page abc/123 goes to 404 abc/std/index.html?... #54952

huonw opened this issue Oct 10, 2018 · 6 comments
Assignees
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@huonw
Copy link
Member

huonw commented Oct 10, 2018

For instance, on https://doc.rust-lang.org/nightly/abc/123, the search box offers to search the standard library for 123. Clicking the search button goes to https://doc.rust-lang.org/nightly/abc/std/index.html?search=123 (note the abc/std) which is invalid. Probably related to
#54609 (cc @GuillaumeGomez).

@kzys
Copy link
Contributor

kzys commented Oct 10, 2018

Ah, my bad. I was assuming that the 404 page wouldn't contain /...

@GuillaumeGomez GuillaumeGomez self-assigned this Oct 10, 2018
@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Oct 10, 2018
@GuillaumeGomez
Copy link
Member

Problem is a bit more complicated than that: we need to keep the version we're looking at (stable, beta or nightly). Not a very complicated fix but still need to be careful. I'll open the PR soon.

@QuietMisdreavus
Copy link
Member

This got brought up again in rust-lang/www.rust-lang.org#864, so it's worth bringing @rust-lang/rustdoc and @rust-lang/docs into this thread as well.

The primary concern is which libstd search to send the user to. doc.rust-lang.org hosts documentation for every version of Rust, so it's possible someone hit a 404 while trying to browse docs for version 1.30.0or the like. Should we redirect them to stable anyway? (Or nightly, since the standard library itself makes other crates link to nightly thanks to itshtml_root_url`?) Should we try to detect which version of Rust they're browsing, and introduce a JavaScript semver parser into our 404 page? (Or have some other means of injecting the version number into the page?) There's not really a clean way to approach this, at least that i can see.

@huonw
Copy link
Member Author

huonw commented Jun 10, 2019

I think the version thing can be maintained from the current page as a "black box" slug without having to parse it? The difficulty would seem to then be deciding whether a URL is versioned (like /nightly/std/... or /1.30.0/std/...) or not (like /std/...), which can potentially be done via checking a list of the known fixed slugs or whether the first slug starts with a number. That might look something like the following (which is untested, and doesn't have appropriate error handling):

const path = new URL(window.location.href).pathname
const firstComponent = path.split('/')[0]
const fixedVersions = ["stable", "beta", "nightly"]
const includeFirst = fixedVersions.includes(firstComponent) || /^[0-9]/.test(firstComponent)

// inside the search submit:

document.location.href = (includeFirst ? "/" + firstComponent : "") + "/std/index.html?search=" ...

@Dylan-DPC
Copy link
Member

This now redirects to this link which works as it's supposed to so closing this

@huonw
Copy link
Member Author

huonw commented Mar 23, 2023

That link https://doc.rust-lang.org/std/index.html?search=123 has lost the version (/nightly/ in the original), which is probably okay, but isn't exactly 'correct'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants