diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-01-03 23:51:20 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-04-18 20:59:08 +0200 |
| commit | 51de26cfd977edc7b0dc5450474a840359a79443 (patch) | |
| tree | 8fa0ad96312db3273a03baa22a50994ea9d45512 | |
| parent | bbcf1762ddd06a895b0bb235fa0718901dc73184 (diff) | |
| download | rust-51de26cfd977edc7b0dc5450474a840359a79443.tar.gz rust-51de26cfd977edc7b0dc5450474a840359a79443.zip | |
* If type filter is in quotes, throw an error.
* If there are generics, don't allow to have quotes.
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 14 | ||||
| -rw-r--r-- | src/test/rustdoc-js-std/parser-errors.js | 28 | ||||
| -rw-r--r-- | src/test/rustdoc-js-std/parser-literal.js | 8 | ||||
| -rw-r--r-- | src/test/rustdoc-js-std/parser-quote.js | 49 | ||||
| -rw-r--r-- | src/test/rustdoc-js/generics.js | 4 |
5 files changed, 45 insertions, 58 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 55d957db333..03518cd5ae8 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -216,11 +216,13 @@ window.initSearch = function(rawSearchIndex) { } function isPathStart(query) { var pos = query.pos; - return pos + 1 < query.length && query.userQuery[pos] === ':' && query.userQuery[pos + 1] === ':'; + return pos + 1 < query.length && query.userQuery[pos] === ':' && + query.userQuery[pos + 1] === ':'; } function isReturnArrow(query) { var pos = query.pos; - return pos + 1 < query.length && query.userQuery[pos] === '-' && query.userQuery[pos + 1] === '>'; + return pos + 1 < query.length && query.userQuery[pos] === '-' && + query.userQuery[pos + 1] === '>'; } function removeEmptyStringsFromArray(x) { for (var i = 0, len = x.length; i < len; ++i) { @@ -235,6 +237,9 @@ window.initSearch = function(rawSearchIndex) { if (name === '*' || (name.length === 0 && generics.length === 0)) { return; } + if (query.literalSearch && query.totalElems > 0) { + throw new Error("You cannot have more than one element if you use quotes"); + } var paths = name.split("::"); removeEmptyStringsFromArray(paths); // In case we only have something like `<p>`, there is no name but it remains valid. @@ -320,6 +325,9 @@ window.initSearch = function(rawSearchIndex) { } else if (c === ":" && query.typeFilter === null && !isPathStart(query) && query.elems.length === 1) { + if (query.literalSearch) { + throw new Error("You cannot use quotes on type filter"); + } // The type filter doesn't count as an element since it's a modifier. query.typeFilter = query.elems.pop().name; query.pos += 1; @@ -400,7 +408,7 @@ window.initSearch = function(rawSearchIndex) { if (!query.literalSearch) { // If there is more than one element in the query, we switch to literalSearch in any // case. - query.literalSearch = query.foundElems > 1; + query.literalSearch = query.totalElems > 1; } if (query.elemName !== null) { query.foundElems += 1; diff --git a/src/test/rustdoc-js-std/parser-errors.js b/src/test/rustdoc-js-std/parser-errors.js index b789fd05d7c..c5d106120ad 100644 --- a/src/test/rustdoc-js-std/parser-errors.js +++ b/src/test/rustdoc-js-std/parser-errors.js @@ -1,4 +1,4 @@ -const QUERY = ['<"P">', '"P" "P"', 'P "P"']; +const QUERY = ['<"P">', '"P" "P"', 'P "P"', '"p" p', '"const": p']; const PARSED = [ { @@ -40,4 +40,30 @@ const PARSED = [ userQuery: "p \"p\"", error: "Cannot use literal search when there is more than one element", }, + { + args: [], + elemName: null, + elems: [], + foundElems: 0, + id: "\"p\" p", + nameSplit: null, + original: "\"p\" p", + returned: [], + typeFilter: null, + userQuery: "\"p\" p", + error: "You cannot have more than one element if you use quotes", + }, + { + args: [], + elemName: null, + elems: [], + foundElems: 0, + id: "\"const\": p", + nameSplit: null, + original: "\"const\": p", + returned: [], + typeFilter: null, + userQuery: "\"const\": p", + error: "You cannot use quotes on type filter", + }, ]; diff --git a/src/test/rustdoc-js-std/parser-literal.js b/src/test/rustdoc-js-std/parser-literal.js index 1a70bafbf5e..f1713fbaf88 100644 --- a/src/test/rustdoc-js-std/parser-literal.js +++ b/src/test/rustdoc-js-std/parser-literal.js @@ -1,4 +1,4 @@ -const QUERY = ['"R"<P>']; +const QUERY = ['R<P>']; const PARSED = [ { @@ -20,12 +20,12 @@ const PARSED = [ ], }], foundElems: 1, - id: "\"R\"<P>", + id: "R<P>", nameSplit: null, - original: "\"R\"<P>", + original: "R<P>", returned: [], typeFilter: -1, - userQuery: "\"r\"<p>", + userQuery: "r<p>", error: null, } ]; diff --git a/src/test/rustdoc-js-std/parser-quote.js b/src/test/rustdoc-js-std/parser-quote.js index aa1b8d3dc64..1c59a3d50ee 100644 --- a/src/test/rustdoc-js-std/parser-quote.js +++ b/src/test/rustdoc-js-std/parser-quote.js @@ -1,4 +1,4 @@ -const QUERY = ['-> "p"', '"const": "p"', '("p")', '"p"<p>']; +const QUERY = ['-> "p"', '("p")']; const PARSED = [ { @@ -20,27 +20,6 @@ const PARSED = [ userQuery: "-> \"p\"", error: null, }, - // This one checks that if quotes are used on the type filter, they're - // simply ignored. - { - args: [], - elemName: null, - elems: [{ - name: "p", - fullPath: ["p"], - pathWithoutLast: [], - pathLast: "p", - generics: [], - }], - foundElems: 1, - id: "\"const\": \"p\"", - nameSplit: null, - original: "\"const\": \"p\"", - returned: [], - typeFilter: 17, - userQuery: "\"const\": \"p\"", - error: null, - }, { args: [{ name: "p", @@ -60,30 +39,4 @@ const PARSED = [ userQuery: "(\"p\")", error: null, }, - // This test checks that a literal item can still have generics. - { - args: [], - elemName: null, - elems: [{ - name: "p", - fullPath: ["p"], - pathWithoutLast: [], - pathLast: "p", - generics: [{ - name: "p", - fullPath: ["p"], - pathWithoutLast: [], - pathLast: "p", - generics: [], - }], - }], - foundElems: 1, - id: "\"p\"<p>", - nameSplit: null, - original: "\"p\"<p>", - returned: [], - typeFilter: -1, - userQuery: "\"p\"<p>", - error: null, - }, ]; diff --git a/src/test/rustdoc-js/generics.js b/src/test/rustdoc-js/generics.js index babfbf98e3e..4aa6b355b6d 100644 --- a/src/test/rustdoc-js/generics.js +++ b/src/test/rustdoc-js/generics.js @@ -1,10 +1,10 @@ // exact-check const QUERY = [ - '"R"<P>', + 'R<P>', '"P"', 'P', - '"ExtraCreditStructMulti"<ExtraCreditInnerMulti, ExtraCreditInnerMulti>', + 'ExtraCreditStructMulti<ExtraCreditInnerMulti, ExtraCreditInnerMulti>', 'TraitCat', 'TraitDog', 'Result<String>', |
