Skip to content

Commit 97280be

Browse files
authored
Rollup merge of #108656 - GuillaumeGomez:rustdoc-search-unclosed-generic, r=notriddle
Rustdoc search: Emit an error for unclosed generic Now, search like `a<` will error as it should (and as written in the eBNF). r? `@notriddle`
2 parents cb81046 + 892d73d commit 97280be

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ function initSearch(rawSearchIndex) {
446446
}
447447
const posBefore = parserState.pos;
448448
getNextElem(query, parserState, elems, endChar === ">");
449+
if (endChar !== "") {
450+
if (parserState.pos >= parserState.length) {
451+
throw new Error("Unclosed `<`");
452+
}
453+
const c2 = parserState.userQuery[parserState.pos];
454+
if (!isSeparatorCharacter(c2) && c2 !== endChar) {
455+
throw new Error(`Expected \`${endChar}\`, found \`${c2}\``);
456+
}
457+
}
449458
// This case can be encountered if `getNextElem` encountered a "stop character" right
450459
// from the start. For example if you have `,,` or `<>`. In this case, we simply move up
451460
// the current position to continue the parsing.
@@ -454,7 +463,10 @@ function initSearch(rawSearchIndex) {
454463
}
455464
foundStopChar = false;
456465
}
457-
// We are either at the end of the string or on the `endChar`` character, let's move forward
466+
if (parserState.pos >= parserState.length && endChar !== "") {
467+
throw new Error("Unclosed `<`");
468+
}
469+
// We are either at the end of the string or on the `endChar` character, let's move forward
458470
// in any case.
459471
parserState.pos += 1;
460472
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const QUERY = [
3939
"a!!",
4040
"mod:a!",
4141
"a!::a",
42+
"a<",
4243
];
4344

4445
const PARSED = [
@@ -402,4 +403,13 @@ const PARSED = [
402403
userQuery: "a!::a",
403404
error: 'Cannot have associated items in macros',
404405
},
406+
{
407+
elems: [],
408+
foundElems: 0,
409+
original: "a<",
410+
returned: [],
411+
typeFilter: -1,
412+
userQuery: "a<",
413+
error: "Unclosed `<`",
414+
},
405415
];

0 commit comments

Comments
 (0)