From 51e976948d6b4c3d16998c83b8ffd1497b0b7d8b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 2 Mar 2023 14:28:06 +0100 Subject: [PATCH 1/2] Emit an error for unclosed generic --- src/librustdoc/html/static/js/search.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 5a46729156d..b98bced4126 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -469,6 +469,15 @@ function initSearch(rawSearchIndex) { } const posBefore = parserState.pos; getNextElem(query, parserState, elems, endChar === ">"); + if (endChar !== "") { + if (parserState.pos >= parserState.length) { + throw ["Unclosed ", "<"]; + } + const c2 = parserState.userQuery[parserState.pos]; + if (!isSeparatorCharacter(c2) && c2 !== endChar) { + throw ["Expected ", endChar, ", found ", c2]; + } + } // This case can be encountered if `getNextElem` encountered a "stop character" right // from the start. For example if you have `,,` or `<>`. In this case, we simply move up // the current position to continue the parsing. @@ -477,7 +486,10 @@ function initSearch(rawSearchIndex) { } foundStopChar = false; } - // We are either at the end of the string or on the `endChar`` character, let's move forward + if (parserState.pos >= parserState.length && endChar !== "") { + throw ["Unclosed ", "<"]; + } + // We are either at the end of the string or on the `endChar` character, let's move forward // in any case. parserState.pos += 1; } From 823671589f3de683d6d2f46fa6c0259d08f6cda5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 2 Mar 2023 14:28:15 +0100 Subject: [PATCH 2/2] Add test for unclosed generic --- tests/rustdoc-js-std/parser-errors.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/rustdoc-js-std/parser-errors.js b/tests/rustdoc-js-std/parser-errors.js index 6c5a7770283..98c6f27ca61 100644 --- a/tests/rustdoc-js-std/parser-errors.js +++ b/tests/rustdoc-js-std/parser-errors.js @@ -39,6 +39,7 @@ const QUERY = [ "a!!", "mod:a!", "a!::a", + "a<", ]; const PARSED = [ @@ -402,4 +403,13 @@ const PARSED = [ userQuery: "a!::a", error: 'Cannot have associated items in macros', }, + { + elems: [], + foundElems: 0, + original: "a<", + returned: [], + typeFilter: -1, + userQuery: "a<", + error: "Unclosed `<`", + }, ];