From e4ee3298656b74dd6be810862b5dd4cb8d2825b8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 13 Jun 2023 14:01:01 +0200 Subject: [PATCH] Fix eBNF and handling of whitespace characters when not in a path --- src/librustdoc/html/static/js/search.js | 13 ++- tests/rustdoc-js-std/parser-errors.js | 106 +++++++++++++++++++++++- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 35abce0903c..009775645f5 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -838,7 +838,13 @@ function initSearch(rawSearchIndex) { throw ["Unexpected ", c]; } else if (c === ":" && !isPathStart(parserState)) { if (parserState.typeFilter !== null) { - throw ["Unexpected ", ":"]; + throw [ + "Unexpected ", + ":", + " (expected path after type filter ", + parserState.typeFilter + ":", + ")", + ]; } else if (query.elems.length === 0) { throw ["Expected type filter before ", ":"]; } else if (query.literalSearch) { @@ -853,6 +859,9 @@ function initSearch(rawSearchIndex) { query.literalSearch = false; foundStopChar = true; continue; + } else if (isWhitespace(c)) { + skipWhitespace(parserState); + continue; } if (!foundStopChar) { let extra = ""; @@ -983,7 +992,7 @@ function initSearch(rawSearchIndex) { * path = ident *(DOUBLE-COLON/{WS} ident) [!] * slice = OPEN-SQUARE-BRACKET [ nonempty-arg-list ] CLOSE-SQUARE-BRACKET * arg = [type-filter *WS COLON *WS] (path [generics] / slice) - * type-sep = COMMA *(COMMA) + * type-sep = *WS COMMA *(COMMA) * nonempty-arg-list = *(type-sep) arg *(type-sep arg) *(type-sep) * generics = OPEN-ANGLE-BRACKET [ nonempty-arg-list ] *(type-sep) * CLOSE-ANGLE-BRACKET diff --git a/tests/rustdoc-js-std/parser-errors.js b/tests/rustdoc-js-std/parser-errors.js index 66b0e516b2b..b32bfea5439 100644 --- a/tests/rustdoc-js-std/parser-errors.js +++ b/tests/rustdoc-js-std/parser-errors.js @@ -366,7 +366,7 @@ const PARSED = [ original: "a<> :", returned: [], userQuery: "a<> :", - error: 'Expected `,`, `:` or `->` after `>`, found ` `', + error: 'Unexpected `<` in type filter (before `:`)', }, { query: "mod : :", @@ -440,4 +440,108 @@ const PARSED = [ userQuery: "a<", error: "Unclosed `<`", }, + { + query: "p , y", + elems: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [ + { + name: "x", + fullPath: ["x"], + pathWithoutLast: [], + pathLast: "x", + generics: [], + typeFilter: -1, + }, + ], + typeFilter: -1, + }, + { + name: "y", + fullPath: ["y"], + pathWithoutLast: [], + pathLast: "y", + generics: [], + typeFilter: -1, + }, + ], + foundElems: 2, + original: "p , y", + returned: [], + userQuery: "p , y", + error: null, + }, + { + query: "p", + elems: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [ + { + name: "x", + fullPath: ["x"], + pathWithoutLast: [], + pathLast: "x", + generics: [], + typeFilter: -1, + }, + { + name: "y", + fullPath: ["y"], + pathWithoutLast: [], + pathLast: "y", + generics: [], + typeFilter: -1, + }, + ], + typeFilter: -1, + }, + ], + foundElems: 1, + original: "p", + returned: [], + userQuery: "p", + error: null, + }, + { + query: "p ,x , y", + elems: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + typeFilter: -1, + }, + { + name: "x", + fullPath: ["x"], + pathWithoutLast: [], + pathLast: "x", + generics: [], + typeFilter: -1, + }, + { + name: "y", + fullPath: ["y"], + pathWithoutLast: [], + pathLast: "y", + generics: [], + typeFilter: -1, + }, + ], + foundElems: 3, + original: "p ,x , y", + returned: [], + userQuery: "p ,x , y", + error: null, + }, ];