Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 51de26c

Browse files
* If type filter is in quotes, throw an error.
* If there are generics, don't allow to have quotes.
1 parent bbcf176 commit 51de26c

File tree

5 files changed

+45
-58
lines changed

5 files changed

+45
-58
lines changed

src/librustdoc/html/static/js/search.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ window.initSearch = function(rawSearchIndex) {
216216
}
217217
function isPathStart(query) {
218218
var pos = query.pos;
219-
return pos + 1 < query.length && query.userQuery[pos] === ':' && query.userQuery[pos + 1] === ':';
219+
return pos + 1 < query.length && query.userQuery[pos] === ':' &&
220+
query.userQuery[pos + 1] === ':';
220221
}
221222
function isReturnArrow(query) {
222223
var pos = query.pos;
223-
return pos + 1 < query.length && query.userQuery[pos] === '-' && query.userQuery[pos + 1] === '>';
224+
return pos + 1 < query.length && query.userQuery[pos] === '-' &&
225+
query.userQuery[pos + 1] === '>';
224226
}
225227
function removeEmptyStringsFromArray(x) {
226228
for (var i = 0, len = x.length; i < len; ++i) {
@@ -235,6 +237,9 @@ window.initSearch = function(rawSearchIndex) {
235237
if (name === '*' || (name.length === 0 && generics.length === 0)) {
236238
return;
237239
}
240+
if (query.literalSearch && query.totalElems > 0) {
241+
throw new Error("You cannot have more than one element if you use quotes");
242+
}
238243
var paths = name.split("::");
239244
removeEmptyStringsFromArray(paths);
240245
// In case we only have something like `<p>`, there is no name but it remains valid.
@@ -320,6 +325,9 @@ window.initSearch = function(rawSearchIndex) {
320325
} else if (c === ":" && query.typeFilter === null && !isPathStart(query) &&
321326
query.elems.length === 1)
322327
{
328+
if (query.literalSearch) {
329+
throw new Error("You cannot use quotes on type filter");
330+
}
323331
// The type filter doesn't count as an element since it's a modifier.
324332
query.typeFilter = query.elems.pop().name;
325333
query.pos += 1;
@@ -400,7 +408,7 @@ window.initSearch = function(rawSearchIndex) {
400408
if (!query.literalSearch) {
401409
// If there is more than one element in the query, we switch to literalSearch in any
402410
// case.
403-
query.literalSearch = query.foundElems > 1;
411+
query.literalSearch = query.totalElems > 1;
404412
}
405413
if (query.elemName !== null) {
406414
query.foundElems += 1;

src/test/rustdoc-js-std/parser-errors.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const QUERY = ['<"P">', '"P" "P"', 'P "P"'];
1+
const QUERY = ['<"P">', '"P" "P"', 'P "P"', '"p" p', '"const": p'];
22

33
const PARSED = [
44
{
@@ -40,4 +40,30 @@ const PARSED = [
4040
userQuery: "p \"p\"",
4141
error: "Cannot use literal search when there is more than one element",
4242
},
43+
{
44+
args: [],
45+
elemName: null,
46+
elems: [],
47+
foundElems: 0,
48+
id: "\"p\" p",
49+
nameSplit: null,
50+
original: "\"p\" p",
51+
returned: [],
52+
typeFilter: null,
53+
userQuery: "\"p\" p",
54+
error: "You cannot have more than one element if you use quotes",
55+
},
56+
{
57+
args: [],
58+
elemName: null,
59+
elems: [],
60+
foundElems: 0,
61+
id: "\"const\": p",
62+
nameSplit: null,
63+
original: "\"const\": p",
64+
returned: [],
65+
typeFilter: null,
66+
userQuery: "\"const\": p",
67+
error: "You cannot use quotes on type filter",
68+
},
4369
];

src/test/rustdoc-js-std/parser-literal.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const QUERY = ['"R"<P>'];
1+
const QUERY = ['R<P>'];
22

33
const PARSED = [
44
{
@@ -20,12 +20,12 @@ const PARSED = [
2020
],
2121
}],
2222
foundElems: 1,
23-
id: "\"R\"<P>",
23+
id: "R<P>",
2424
nameSplit: null,
25-
original: "\"R\"<P>",
25+
original: "R<P>",
2626
returned: [],
2727
typeFilter: -1,
28-
userQuery: "\"r\"<p>",
28+
userQuery: "r<p>",
2929
error: null,
3030
}
3131
];
Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const QUERY = ['-> "p"', '"const": "p"', '("p")', '"p"<p>'];
1+
const QUERY = ['-> "p"', '("p")'];
22

33
const PARSED = [
44
{
@@ -20,27 +20,6 @@ const PARSED = [
2020
userQuery: "-> \"p\"",
2121
error: null,
2222
},
23-
// This one checks that if quotes are used on the type filter, they're
24-
// simply ignored.
25-
{
26-
args: [],
27-
elemName: null,
28-
elems: [{
29-
name: "p",
30-
fullPath: ["p"],
31-
pathWithoutLast: [],
32-
pathLast: "p",
33-
generics: [],
34-
}],
35-
foundElems: 1,
36-
id: "\"const\": \"p\"",
37-
nameSplit: null,
38-
original: "\"const\": \"p\"",
39-
returned: [],
40-
typeFilter: 17,
41-
userQuery: "\"const\": \"p\"",
42-
error: null,
43-
},
4423
{
4524
args: [{
4625
name: "p",
@@ -60,30 +39,4 @@ const PARSED = [
6039
userQuery: "(\"p\")",
6140
error: null,
6241
},
63-
// This test checks that a literal item can still have generics.
64-
{
65-
args: [],
66-
elemName: null,
67-
elems: [{
68-
name: "p",
69-
fullPath: ["p"],
70-
pathWithoutLast: [],
71-
pathLast: "p",
72-
generics: [{
73-
name: "p",
74-
fullPath: ["p"],
75-
pathWithoutLast: [],
76-
pathLast: "p",
77-
generics: [],
78-
}],
79-
}],
80-
foundElems: 1,
81-
id: "\"p\"<p>",
82-
nameSplit: null,
83-
original: "\"p\"<p>",
84-
returned: [],
85-
typeFilter: -1,
86-
userQuery: "\"p\"<p>",
87-
error: null,
88-
},
8942
];

src/test/rustdoc-js/generics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// exact-check
22

33
const QUERY = [
4-
'"R"<P>',
4+
'R<P>',
55
'"P"',
66
'P',
7-
'"ExtraCreditStructMulti"<ExtraCreditInnerMulti, ExtraCreditInnerMulti>',
7+
'ExtraCreditStructMulti<ExtraCreditInnerMulti, ExtraCreditInnerMulti>',
88
'TraitCat',
99
'TraitDog',
1010
'Result<String>',

0 commit comments

Comments
 (0)