Skip to content

Commit 68bcd90

Browse files
authored
Rollup merge of #147860 - lolbinarycat:rustdoc-search-relax-ident-rules, r=notriddle,GuillaumeGomez
rustdoc search: relax rules for identifiers fixes #147763
2 parents 8cd557d + a354992 commit 68bcd90

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ const ROOT_PATH = typeof window !== "undefined" ? window.rootPath : "../";
149149
const UNBOXING_LIMIT = 5;
150150

151151
// used for search query verification
152-
const REGEX_IDENT = /\p{ID_Start}\p{ID_Continue}*|_\p{ID_Continue}+/uy;
152+
// because searches are often performed using substrings of identifiers,
153+
// and not just full identiferes, we allow them to start with chars that otherwise
154+
// can only appear in the middle of identifiers
155+
const REGEX_IDENT = /\p{ID_Continue}+/uy;
153156
const REGEX_INVALID_TYPE_FILTER = /[^a-z]/ui;
154157

155158
const MAX_RESULTS = 200;

tests/rustdoc-js-std/parser-errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const PARSED = [
165165
foundElems: 0,
166166
userQuery: "_:",
167167
returned: [],
168-
error: "Unexpected `_` (not a valid identifier)",
168+
error: "Unexpected `_` in type filter (before `:`)",
169169
},
170170
{
171171
query: "ab:",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// regression test for https://github.com/rust-lang/rust/issues/147763
2+
//
3+
// identifiers in search queries should not be required to follow the
4+
// same strict rules around ID_Start that identifers in rust code follow,
5+
// as searches frequently use substrings of identifers.
6+
//
7+
// for example, identifiers cannot start with digits,
8+
// but they can contain them, so we allow search idents to start with digits.
9+
10+
const EXPECTED = {
11+
'query': '8',
12+
'others': [
13+
{
14+
'path': 'std',
15+
'name': 'i8',
16+
'href': '../std/primitive.i8.html',
17+
},
18+
]
19+
};

0 commit comments

Comments
 (0)