Skip to content

Commit ebfadd7

Browse files
committed
Fix no results when searching for == in doc
1 parent f57eac1 commit ebfadd7

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

src/librustdoc/html/static/js/search.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,9 +1556,10 @@ class DocSearch {
15561556
return query;
15571557
}
15581558
if (!query.literalSearch) {
1559-
// If there is more than one element in the query, we switch to literalSearch in any
1560-
// case.
1561-
query.literalSearch = parserState.totalElems > 1;
1559+
// If there is more than one element or only separators in the query,
1560+
// we switch to literalSearch in any case.
1561+
query.literalSearch = parserState.totalElems > 1 ||
1562+
userQuery.replace(/[=, ]/g, "") === "";
15621563
}
15631564
query.foundElems = query.elems.length + query.returned.length;
15641565
query.totalElems = parserState.totalElems;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/150921
2+
//
3+
// Ensure `?search===` (unencoded value `==`) round-trips through query-string parsing so
4+
// `==` searches work.
5+
include: "utils.goml"
6+
7+
// NOTE: This intentionally uses an *unencoded* value of `==`.
8+
// In a query string, that means `?search===` (one '=' for the delimiter, two for the value).
9+
go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search==="
10+
11+
// Wait for search results to be available.
12+
wait-for: "#crate-search"
13+
wait-for-false: "#search-tabs .count.loading"
14+
15+
// `OperatorEqEqAlias` has `#[doc(alias = "==")]`.
16+
wait-for: "//a[contains(@href,'struct.OperatorEqEqAlias.html')]"
17+
assert: "//a[contains(@href,'struct.OperatorEqEqAlias.html')]"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/150921
2+
//
3+
// Ensure `?search=!=` (unencoded value `!=`) round-trips through query-string parsing so
4+
// `!=` searches work.
5+
include: "utils.goml"
6+
7+
// NOTE: This intentionally uses an *unencoded* value of `!=`.
8+
// In a query string, that means `?search=!=` (one '=' for the delimiter, one for the value).
9+
go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=!="
10+
11+
// Wait for search results to be available.
12+
wait-for: "#crate-search"
13+
wait-for-false: "#search-tabs .count.loading"
14+
15+
// `OperatorNotEqAlias` has `#[doc(alias = "!=")]`.
16+
wait-for: "//a[contains(@href,'struct.OperatorNotEqAlias.html')]"
17+
assert: "//a[contains(@href,'struct.OperatorNotEqAlias.html')]"

tests/rustdoc-gui/src/lib2/lib.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ pub mod module {
1616
pub fn whatever() {}
1717
}
1818

19+
#[doc(alias = "==")]
20+
pub struct OperatorEqEqAlias;
21+
22+
#[doc(alias = "!=")]
23+
pub struct OperatorNotEqAlias;
24+
1925
pub fn foobar() {}
2026

2127
pub type Alias = u32;
@@ -149,14 +155,30 @@ pub trait LongTraitWithParamsBananaBananaBanana<T> {}
149155

150156
impl LongTraitWithParamsBananaBananaBanana<usize> for HasALongTraitWithParams {}
151157

152-
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
158+
#[doc(cfg(any(
159+
target_os = "android",
160+
target_os = "linux",
161+
target_os = "emscripten",
162+
target_os = "dragonfly",
163+
target_os = "freebsd",
164+
target_os = "netbsd",
165+
target_os = "openbsd"
166+
)))]
153167
pub struct LongItemInfo;
154168

155169
pub trait SimpleTrait {}
156170
pub struct LongItemInfo2;
157171

158172
/// Some docs.
159-
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
173+
#[doc(cfg(any(
174+
target_os = "android",
175+
target_os = "linux",
176+
target_os = "emscripten",
177+
target_os = "dragonfly",
178+
target_os = "freebsd",
179+
target_os = "netbsd",
180+
target_os = "openbsd"
181+
)))]
160182
impl SimpleTrait for LongItemInfo2 {}
161183

162184
pub struct WhereWhitespace<T>(T);
@@ -165,7 +187,9 @@ impl<T> WhereWhitespace<T> {
165187
pub fn new<F>(f: F) -> Self
166188
where
167189
F: FnMut() -> i32,
168-
{todo!()}
190+
{
191+
todo!()
192+
}
169193
}
170194

171195
impl<K, T> Whitespace<&K> for WhereWhitespace<T>

0 commit comments

Comments
 (0)