Skip to content

Fix JS search scripts path #145650

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
Aug 21, 2025

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Aug 20, 2025

rootPath always end with a / so we should not add one. Interestingly enough, it only triggers the bug on a website (like https://doc.rust-lang.org/nightly/std/).

Follow-up of #144476.
Fixes #145646.

cc @notriddle
r? @fmease

@rustbot
Copy link
Collaborator

rustbot commented Aug 20, 2025

fmease is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added A-rustdoc-search Area: Rustdoc's search feature S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Aug 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 20, 2025

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha, @lolbinarycat

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the fix-js-search-scripts-path branch from d15d582 to e1045c2 Compare August 20, 2025 10:57
@fmease
Copy link
Member

fmease commented Aug 20, 2025

Interestingly enough, it only triggers the bug on a website

Locally, if we're dealing with file://, the URL also contains double slashes (e.g, file:///home/fmease/programming/rust/rustc3/doc//search.index/path/d30b089bc95f.js) but at least on Linux consecutive slashes get normalized to a single one, so it ends up resolving.

Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I've manually gone through all references of ROOT_PATH and "DocSearch#rootPath" (set to ROOT_PATH in the ctor) and all other sites seem to append path segments correctly (i.e., without an extra slash).

@fmease
Copy link
Member

fmease commented Aug 20, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 20, 2025

📌 Commit e1045c2 has been approved by fmease

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 20, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 20, 2025
…ts-path, r=fmease

Fix JS search scripts path

`rootPath` always end with a `/` so we should not add one. Interestingly enough, it only triggers the bug on a website (like https://doc.rust-lang.org/nightly/std/).

Follow-up of rust-lang#144476.
Fixes rust-lang#145646.

cc `@notriddle`
r? `@fmease`
@Zalathar
Copy link
Contributor

I've taken the liberty of rolling this up (despite the backlog) because I think it's worthwhile to get doc search working again ASAP.

bors added a commit that referenced this pull request Aug 20, 2025
Rollup of 5 pull requests

Successful merges:

 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145647 (miri subtree update)
 - #145650 (Fix JS search scripts path)

r? `@ghost`
`@rustbot` modify labels: rollup
@lolbinarycat
Copy link
Contributor

Locally, if we're dealing with file://, the URL also contains double slashes (e.g, file:///home/fmease/programming/rust/rustc3/doc//search.index/path/d30b089bc95f.js) but at least on Linux consecutive slashes get normalized to a single one, so it ends up resolving.

most http servers also deduplicate consecutive slashes, but apparently not the one that rust documentation is hosted on.

@blyxyas
Copy link
Member

blyxyas commented Aug 20, 2025

It also affected docs.rs, so Axum doesn't deduplicate slashes it seems.
tokio-rs/axum#714 might be related?

@fmease
Copy link
Member

fmease commented Aug 20, 2025

That just means that rustdoc can't assume that consecutive slashes get normalized away by whomever ends up interpreting the path.

@lolbinarycat
Copy link
Contributor

That just means that rustdoc can't assume that consecutive slashes get normalized away by whomever ends up interpreting the path.

Is there a way we can modify the gui testing framework to error if there are ever duplicated slashes in the URL path? that seems desirable to stop this from happening again.

@fmease
Copy link
Member

fmease commented Aug 20, 2025

CC https://en.wikipedia.org/wiki/URI_normalization which classifies "slash collapsing" to not necessarily be semantics-preserving.

@notriddle
Copy link
Contributor

Yes. I'll have a PR open that tests this in a few minutes.

jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 20, 2025
…ts-path, r=fmease

Fix JS search scripts path

`rootPath` always end with a `/` so we should not add one. Interestingly enough, it only triggers the bug on a website (like https://doc.rust-lang.org/nightly/std/).

Follow-up of rust-lang#144476.
Fixes rust-lang#145646.

cc `@notriddle`
r? `@fmease`
bors added a commit that referenced this pull request Aug 20, 2025
Rollup of 12 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144443 (Make target pointer width in target json an integer)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145573 (Add an experimental unsafe(force_target_feature) attribute.)
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145674 (Enable triagebot `[review-changes-since]` feature)

Failed merges:

 - #145647 (miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 20, 2025
…ts-path, r=fmease

Fix JS search scripts path

`rootPath` always end with a `/` so we should not add one. Interestingly enough, it only triggers the bug on a website (like https://doc.rust-lang.org/nightly/std/).

Follow-up of rust-lang#144476.
Fixes rust-lang#145646.

cc ``@notriddle``
r? ``@fmease``
bors added a commit that referenced this pull request Aug 20, 2025
Rollup of 14 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144443 (Make target pointer width in target json an integer)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145137 (Consolidate panicking functions in `slice/index.rs`)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145297 (fix(debuginfo): handle false positives in overflow check)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145674 (Enable triagebot `[review-changes-since]` feature)
 - #145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 21, 2025
…ts-path, r=fmease

Fix JS search scripts path

`rootPath` always end with a `/` so we should not add one. Interestingly enough, it only triggers the bug on a website (like https://doc.rust-lang.org/nightly/std/).

Follow-up of rust-lang#144476.
Fixes rust-lang#145646.

cc ```@notriddle```
r? ```@fmease```
bors added a commit that referenced this pull request Aug 21, 2025
Rollup of 15 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145137 (Consolidate panicking functions in `slice/index.rs`)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145297 (fix(debuginfo): handle false positives in overflow check)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145590 (Prevent impossible combinations in `ast::ModKind`.)
 - #145621 (Fix some doc typos)
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145674 (Enable triagebot `[review-changes-since]` feature)
 - #145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 21, 2025
…ts-path, r=fmease

Fix JS search scripts path

`rootPath` always end with a `/` so we should not add one. Interestingly enough, it only triggers the bug on a website (like https://doc.rust-lang.org/nightly/std/).

Follow-up of rust-lang#144476.
Fixes rust-lang#145646.

cc ````@notriddle````
r? ````@fmease````
bors added a commit that referenced this pull request Aug 21, 2025
Rollup of 19 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145297 (fix(debuginfo): handle false positives in overflow check)
 - #145390 (Shorten some dependency chains in the compiler)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145525 (stdlib: Replace typedef -> type alias in doc comment)
 - #145590 (Prevent impossible combinations in `ast::ModKind`.)
 - #145593 (UnsafePinned::raw_get: sync signature with get)
 - #145621 (Fix some doc typos)
 - #145627 (Unconditionally-const supertraits are considered not dyn compatible)
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145673 (Add flock support for cygwin)
 - #145674 (Enable triagebot `[review-changes-since]` feature)
 - #145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5ea203a into rust-lang:master Aug 21, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 21, 2025
rust-timer added a commit that referenced this pull request Aug 21, 2025
Rollup merge of #145650 - GuillaumeGomez:fix-js-search-scripts-path, r=fmease

Fix JS search scripts path

`rootPath` always end with a `/` so we should not add one. Interestingly enough, it only triggers the bug on a website (like https://doc.rust-lang.org/nightly/std/).

Follow-up of #144476.
Fixes #145646.

cc `````@notriddle`````
r? `````@fmease`````
@GuillaumeGomez GuillaumeGomez deleted the fix-js-search-scripts-path branch August 21, 2025 10:22
@BergmannAtmet
Copy link

A safer way to construct paths needs to be used in my humble opinion, so this doesn't keep happening.

That crates.io issue was Rust code which should have just used Url::join() or whatever. And I'm sure similar solutions exist for JS too.

@GuillaumeGomez
Copy link
Member Author

Thank you unknown person from the internet. I'm sure you commented with good intentions but sadly, there are some issues with your comment:

  1. crates.io codebase and rustdoc codebase are completely separate, and one issue impacting a side might have a very different cause than on the other (which is actually exactly the case here).
  2. There doesn't seem to have a provided way to do that in web browsers directly, otherwise it would be much simpler to handle that.
  3. // is valid in URLs, and sometimes the web server replaces them with one slash, sometimes it doesn't, hence why we didn't realize until we actually ended up generating docs on a server which actually keeps the double slash.

This PR fixes the issue and and most importantly: a follow-up (#145669) will add a regression test to ensure it doesn't happen again.

So now comes the "wise man talk": comments are very welcome, but considering how stressful this has been for the people involved, if you just come in saying "why are you so bad at doing this thing?", it's just annoying and counter-productive. However if you came with a useful information like "you could use this vanilla JS method to handle paths", then we'd be very happy.

@BergmannAtmet
Copy link

@GuillaumeGomez

I don't do JS, so I assumed people familiar with it would know better.

Having said that, this seems to work.

(I wrote a silly and technically wrong comment earlier which I promptly deleted.)

@notriddle
Copy link
Contributor

I think it would make more sense to use the URL interface from the DOM. The Rustdoc frontend has no build step, and I'd prefer not to add one.

jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 22, 2025
…ath, r=GuillaumeGomez

rustdoc-search: GUI tests check for `//` in URL

Follow up rust-lang#145650

When this fails, you get output that looks like:

    /home/user/rust/tests/rustdoc-gui/search-result-impl-disambiguation.goml search-result-impl-disambiguation... FAILED
    [ERROR] `tests/rustdoc-gui/utils.goml` around line 49
        from `tests/rustdoc-gui/search-result-impl-disambiguation.goml` line 25: JS errors occurred: Event: Event

Making the error message more informative requires patching browser-ui-test.
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 23, 2025
…ath, r=GuillaumeGomez

rustdoc-search: GUI tests check for `//` in URL

Follow up rust-lang#145650

When this fails, you get output that looks like:

    /home/user/rust/tests/rustdoc-gui/search-result-impl-disambiguation.goml search-result-impl-disambiguation... FAILED
    [ERROR] `tests/rustdoc-gui/utils.goml` around line 49
        from `tests/rustdoc-gui/search-result-impl-disambiguation.goml` line 25: JS errors occurred: Event: Event

Making the error message more informative requires patching browser-ui-test.
rust-timer added a commit that referenced this pull request Aug 23, 2025
Rollup merge of #145669 - notriddle:test-js-search-scripts-path, r=GuillaumeGomez

rustdoc-search: GUI tests check for `//` in URL

Follow up #145650

When this fails, you get output that looks like:

    /home/user/rust/tests/rustdoc-gui/search-result-impl-disambiguation.goml search-result-impl-disambiguation... FAILED
    [ERROR] `tests/rustdoc-gui/utils.goml` around line 49
        from `tests/rustdoc-gui/search-result-impl-disambiguation.goml` line 25: JS errors occurred: Event: Event

Making the error message more informative requires patching browser-ui-test.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 24, 2025
…illaumeGomez

rustdoc-search: GUI tests check for `//` in URL

Follow up rust-lang/rust#145650

When this fails, you get output that looks like:

    /home/user/rust/tests/rustdoc-gui/search-result-impl-disambiguation.goml search-result-impl-disambiguation... FAILED
    [ERROR] `tests/rustdoc-gui/utils.goml` around line 49
        from `tests/rustdoc-gui/search-result-impl-disambiguation.goml` line 25: JS errors occurred: Event: Event

Making the error message more informative requires patching browser-ui-test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-search Area: Rustdoc's search feature S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search loads indefinitely in doc.rust-lang.org/nightly due to 404