diff options
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 21 | ||||
| -rw-r--r-- | src/test/rustdoc-js-std/parser-errors.js | 10 | ||||
| -rw-r--r-- | src/test/rustdoc-js-std/parser-separators.js | 206 | ||||
| -rw-r--r-- | src/tools/rustdoc-js/tester.js | 2 |
4 files changed, 235 insertions, 4 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 239fef494ad..7a318cbfa45 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -227,6 +227,17 @@ window.initSearch = function(rawSearchIndex) { } /** + * Returns `true` if the given `c` character is a separator. + * + * @param {string} c + * + * @return {boolean} + */ + function isSeparatorCharacter(c) { + return ", \t".indexOf(c) !== -1; + } + + /** * @param {ParsedQuery} query * @param {ParserState} parserState * @param {string} name - Name of the query element. @@ -295,7 +306,11 @@ window.initSearch = function(rawSearchIndex) { if (!isIdentCharacter(c)) { if (isErrorCharacter(c)) { throw new Error(`Unexpected \`${c}\``); - } else if (isStopCharacter(c) || isSpecialStartCharacter(c)) { + } else if ( + isStopCharacter(c) || + isSpecialStartCharacter(c) || + isSeparatorCharacter(c)) + { break; } // If we allow paths ("str::string" for example). @@ -358,7 +373,7 @@ window.initSearch = function(rawSearchIndex) { var c = parserState.userQuery[parserState.pos]; if (c === endChar) { break; - } else if (c === "," || c === " ") { + } else if (isSeparatorCharacter(c)) { parserState.pos += 1; foundStopChar = true; continue; @@ -409,7 +424,7 @@ window.initSearch = function(rawSearchIndex) { c = parserState.userQuery[parserState.pos]; if (isStopCharacter(c)) { foundStopChar = true; - if (c === "," || c === " ") { + if (isSeparatorCharacter(c)) { parserState.pos += 1; continue; } else if (c === "-" || c === ">") { diff --git a/src/test/rustdoc-js-std/parser-errors.js b/src/test/rustdoc-js-std/parser-errors.js index bd024a932a1..7b7ca4dbc35 100644 --- a/src/test/rustdoc-js-std/parser-errors.js +++ b/src/test/rustdoc-js-std/parser-errors.js @@ -27,6 +27,7 @@ const QUERY = [ "aaaaa<>b", "fn:aaaaa<>b", "->a<>b", + "a<->", ]; const PARSED = [ @@ -282,4 +283,13 @@ const PARSED = [ userQuery: '->a<>b', error: 'Expected `,` or ` `, found `b`', }, + { + elems: [], + foundElems: 0, + original: 'a<->', + returned: [], + typeFilter: -1, + userQuery: 'a<->', + error: 'Unexpected `-` after `<`', + }, ]; diff --git a/src/test/rustdoc-js-std/parser-separators.js b/src/test/rustdoc-js-std/parser-separators.js new file mode 100644 index 00000000000..5b7abdfa8d6 --- /dev/null +++ b/src/test/rustdoc-js-std/parser-separators.js @@ -0,0 +1,206 @@ +// ignore-tidy-tab + +const QUERY = [ + 'aaaaaa b', + 'a b', + 'a,b', + 'a\tb', + 'a<b c>', + 'a<b,c>', + 'a<b\tc>', +]; + +const PARSED = [ + { + elems: [ + { + name: 'aaaaaa', + fullPath: ['aaaaaa'], + pathWithoutLast: [], + pathLast: 'aaaaaa', + generics: [], + }, + { + name: 'b', + fullPath: ['b'], + pathWithoutLast: [], + pathLast: 'b', + generics: [], + }, + ], + foundElems: 2, + original: "aaaaaa b", + returned: [], + typeFilter: -1, + userQuery: "aaaaaa b", + error: null, + }, + { + elems: [ + { + name: 'a', + fullPath: ['a'], + pathWithoutLast: [], + pathLast: 'a', + generics: [], + }, + { + name: 'b', + fullPath: ['b'], + pathWithoutLast: [], + pathLast: 'b', + generics: [], + }, + ], + foundElems: 2, + original: "a b", + returned: [], + typeFilter: -1, + userQuery: "a b", + error: null, + }, + { + elems: [ + { + name: 'a', + fullPath: ['a'], + pathWithoutLast: [], + pathLast: 'a', + generics: [], + }, + { + name: 'b', + fullPath: ['b'], + pathWithoutLast: [], + pathLast: 'b', + generics: [], + }, + ], + foundElems: 2, + original: "a,b", + returned: [], + typeFilter: -1, + userQuery: "a,b", + error: null, + }, + { + elems: [ + { + name: 'a', + fullPath: ['a'], + pathWithoutLast: [], + pathLast: 'a', + generics: [], + }, + { + name: 'b', + fullPath: ['b'], + pathWithoutLast: [], + pathLast: 'b', + generics: [], + }, + ], + foundElems: 2, + original: "a\tb", + returned: [], + typeFilter: -1, + userQuery: "a\tb", + error: null, + }, + { + elems: [ + { + name: 'a', + fullPath: ['a'], + pathWithoutLast: [], + pathLast: 'a', + generics: [ + { + name: 'b', + fullPath: ['b'], + pathWithoutLast: [], + pathLast: 'b', + generics: [], + }, + { + name: 'c', + fullPath: ['c'], + pathWithoutLast: [], + pathLast: 'c', + generics: [], + }, + ], + }, + ], + foundElems: 1, + original: "a<b c>", + returned: [], + typeFilter: -1, + userQuery: "a<b c>", + error: null, + }, + { + elems: [ + { + name: 'a', + fullPath: ['a'], + pathWithoutLast: [], + pathLast: 'a', + generics: [ + { + name: 'b', + fullPath: ['b'], + pathWithoutLast: [], + pathLast: 'b', + generics: [], + }, + { + name: 'c', + fullPath: ['c'], + pathWithoutLast: [], + pathLast: 'c', + generics: [], + }, + ], + }, + ], + foundElems: 1, + original: "a<b,c>", + returned: [], + typeFilter: -1, + userQuery: "a<b,c>", + error: null, + }, + { + elems: [ + { + name: 'a', + fullPath: ['a'], + pathWithoutLast: [], + pathLast: 'a', + generics: [ + { + name: 'b', + fullPath: ['b'], + pathWithoutLast: [], + pathLast: 'b', + generics: [], + }, + { + name: 'c', + fullPath: ['c'], + pathWithoutLast: [], + pathLast: 'c', + generics: [], + }, + ], + }, + ], + foundElems: 1, + original: "a<b\tc>", + returned: [], + typeFilter: -1, + userQuery: "a<b\tc>", + error: null, + }, +]; diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index d5209089892..042581ac7ad 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -275,7 +275,7 @@ function loadSearchJsAndIndex(searchJs, searchIndex, storageJs, crate) { "parseInput", "getItemsBefore", "getNextElem", "createQueryElement", "isReturnArrow", "isPathStart", "getStringElem", "newParsedQuery", "itemTypeFromName", "isEndCharacter", "isErrorCharacter", - "isIdentCharacter"]; + "isIdentCharacter", "isSeparatorCharacter"]; const functions = ["hasOwnPropertyRustdoc", "onEach"]; ALIASES = {}; |
