From 243dff858fbad519ed21610bef8dadadb5fb69bd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 25 Feb 2023 15:38:06 +0100 Subject: [PATCH 1/2] Prevent to have more than one exclamation mark in a search path --- src/librustdoc/html/static/js/search.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 1e6c94d29ba47..358bc82b98137 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -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}\``); } @@ -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) From bdf1052fd263b08912fa3b53dd3982d6dd877be1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 25 Feb 2023 16:02:56 +0100 Subject: [PATCH 2/2] Update test to ensure exclamation marks can only be at the end of a search path --- tests/rustdoc-js-std/parser-ident.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/tests/rustdoc-js-std/parser-ident.js b/tests/rustdoc-js-std/parser-ident.js index 4b5ab01ac761b..ceee31c3a3f54 100644 --- a/tests/rustdoc-js-std/parser-ident.js +++ b/tests/rustdoc-js-std/parser-ident.js @@ -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 `::`", }, ];