Skip to content

rustdoc: Prevent to have more than one exclamation mark in a search path #108455

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,11 @@ function initSearch(rawSearchIndex) {
} else if (c === ":") { // If we allow paths ("str::string" for example).
if (!isPathStart(parserState)) {
break;
} else if (foundExclamation) {
throw new Error("`!` cannot be followed by `::`");
}
// Skip current ":".
parserState.pos += 1;
foundExclamation = false;
} else {
throw new Error(`Unexpected \`${c}\``);
}
Expand Down Expand Up @@ -591,8 +592,8 @@ function initSearch(rawSearchIndex) {
*
* The supported syntax by this parser is as follow:
*
* ident = *(ALPHA / DIGIT / "_") [!]
* path = ident *(DOUBLE-COLON ident)
* ident = *(ALPHA / DIGIT / "_")
* path = ident *(DOUBLE-COLON ident) [!]
* arg = path [generics]
* arg-without-generic = path
* type-sep = COMMA/WS *(COMMA/WS)
Expand Down
24 changes: 6 additions & 18 deletions tests/rustdoc-js-std/parser-ident.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,21 @@ const PARSED = [
error: null,
},
{
elems: [{
name: "a!::b",
fullPath: ["a!", "b"],
pathWithoutLast: ["a!"],
pathLast: "b",
generics: [],
}],
foundElems: 1,
elems: [],
foundElems: 0,
original: "a!::b",
returned: [],
typeFilter: -1,
userQuery: "a!::b",
error: null,
error: "`!` cannot be followed by `::`",
},
{
elems: [{
name: "a!::b!",
fullPath: ["a!", "b!"],
pathWithoutLast: ["a!"],
pathLast: "b!",
generics: [],
}],
foundElems: 1,
elems: [],
foundElems: 0,
original: "a!::b!",
returned: [],
typeFilter: -1,
userQuery: "a!::b!",
error: null,
error: "`!` cannot be followed by `::`",
},
];