From 45cdb2be10756f584540f349a379730c43fe0976 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 26 Apr 2022 13:58:23 +0200 Subject: [PATCH] Update rustdoc search parser to handle `!` correctly --- src/librustdoc/html/static/js/search.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index c4e74ea0657..c1d2ec540b0 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -310,10 +310,20 @@ window.initSearch = function(rawSearchIndex) { */ function getIdentEndPosition(parserState) { let end = parserState.pos; + let foundExclamation = false; while (parserState.pos < parserState.length) { const c = parserState.userQuery[parserState.pos]; if (!isIdentCharacter(c)) { - if (isErrorCharacter(c)) { + if (c === "!") { + if (foundExclamation) { + throw new Error("Cannot have more than one `!` in an ident"); + } else if (parserState.pos + 1 < parserState.length && + isIdentCharacter(parserState.userQuery[parserState.pos + 1])) + { + throw new Error("`!` can only be at the end of an ident"); + } + foundExclamation = true; + } else if (isErrorCharacter(c)) { throw new Error(`Unexpected \`${c}\``); } else if ( isStopCharacter(c) || @@ -329,6 +339,7 @@ window.initSearch = function(rawSearchIndex) { } // Skip current ":". parserState.pos += 1; + foundExclamation = false; } else { throw new Error(`Unexpected \`${c}\``); } @@ -591,7 +602,7 @@ window.initSearch = function(rawSearchIndex) { * * The supported syntax by this parser is as follow: * - * ident = *(ALPHA / DIGIT / "_") + * ident = *(ALPHA / DIGIT / "_") [!] * path = ident *(DOUBLE-COLON ident) * arg = path [generics] * arg-without-generic = path