Skip to content

Commit 97e6ef3

Browse files
committed
rustdoc search: relax rules for identifiers
1 parent e100792 commit 97e6ef3

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// regression test for https://github.com/rust-lang/rust/issues/147763
2+
3+
const EXPECTED = {
4+
'query': '8',
5+
'others': [
6+
{
7+
'path': 'std',
8+
'name': 'i8',
9+
'href': '../std/primitive.i8.html',
10+
},
11+
]
12+
};

0 commit comments

Comments
 (0)