From a35499268eeda40d9a9c9388f54df548d0dd405e Mon Sep 17 00:00:00 2001 From: binarycat Date: Sat, 18 Oct 2025 15:13:36 -0500 Subject: [PATCH] rustdoc search: relax rules for identifiers --- src/librustdoc/html/static/js/search.js | 5 ++++- tests/rustdoc-js-std/parser-errors.js | 2 +- tests/rustdoc-js-std/search-by-number.js | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/rustdoc-js-std/search-by-number.js diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 0929d351463cc..337c973a2c84f 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -149,7 +149,10 @@ const ROOT_PATH = typeof window !== "undefined" ? window.rootPath : "../"; const UNBOXING_LIMIT = 5; // used for search query verification -const REGEX_IDENT = /\p{ID_Start}\p{ID_Continue}*|_\p{ID_Continue}+/uy; +// because searches are often performed using substrings of identifiers, +// and not just full identiferes, we allow them to start with chars that otherwise +// can only appear in the middle of identifiers +const REGEX_IDENT = /\p{ID_Continue}+/uy; const REGEX_INVALID_TYPE_FILTER = /[^a-z]/ui; const MAX_RESULTS = 200; diff --git a/tests/rustdoc-js-std/parser-errors.js b/tests/rustdoc-js-std/parser-errors.js index 6e11dda8532fa..612118607b5cc 100644 --- a/tests/rustdoc-js-std/parser-errors.js +++ b/tests/rustdoc-js-std/parser-errors.js @@ -165,7 +165,7 @@ const PARSED = [ foundElems: 0, userQuery: "_:", returned: [], - error: "Unexpected `_` (not a valid identifier)", + error: "Unexpected `_` in type filter (before `:`)", }, { query: "ab:", diff --git a/tests/rustdoc-js-std/search-by-number.js b/tests/rustdoc-js-std/search-by-number.js new file mode 100644 index 0000000000000..9d1cb5314dcaa --- /dev/null +++ b/tests/rustdoc-js-std/search-by-number.js @@ -0,0 +1,19 @@ +// regression test for https://github.com/rust-lang/rust/issues/147763 +// +// identifiers in search queries should not be required to follow the +// same strict rules around ID_Start that identifers in rust code follow, +// as searches frequently use substrings of identifers. +// +// for example, identifiers cannot start with digits, +// but they can contain them, so we allow search idents to start with digits. + +const EXPECTED = { + 'query': '8', + 'others': [ + { + 'path': 'std', + 'name': 'i8', + 'href': '../std/primitive.i8.html', + }, + ] +};