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

Commit e03a950

Browse files
Handle separators in their own functions and fix missing handling of tabs
1 parent da829d8 commit e03a950

File tree

4 files changed

+235
-4
lines changed

4 files changed

+235
-4
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ window.initSearch = function(rawSearchIndex) {
226226
(c >= 'A' && c <= 'Z'));
227227
}
228228

229+
/**
230+
* Returns `true` if the given `c` character is a separator.
231+
*
232+
* @param {string} c
233+
*
234+
* @return {boolean}
235+
*/
236+
function isSeparatorCharacter(c) {
237+
return ", \t".indexOf(c) !== -1;
238+
}
239+
229240
/**
230241
* @param {ParsedQuery} query
231242
* @param {ParserState} parserState
@@ -295,7 +306,11 @@ window.initSearch = function(rawSearchIndex) {
295306
if (!isIdentCharacter(c)) {
296307
if (isErrorCharacter(c)) {
297308
throw new Error(`Unexpected \`${c}\``);
298-
} else if (isStopCharacter(c) || isSpecialStartCharacter(c)) {
309+
} else if (
310+
isStopCharacter(c) ||
311+
isSpecialStartCharacter(c) ||
312+
isSeparatorCharacter(c))
313+
{
299314
break;
300315
}
301316
// If we allow paths ("str::string" for example).
@@ -358,7 +373,7 @@ window.initSearch = function(rawSearchIndex) {
358373
var c = parserState.userQuery[parserState.pos];
359374
if (c === endChar) {
360375
break;
361-
} else if (c === "," || c === " ") {
376+
} else if (isSeparatorCharacter(c)) {
362377
parserState.pos += 1;
363378
foundStopChar = true;
364379
continue;
@@ -409,7 +424,7 @@ window.initSearch = function(rawSearchIndex) {
409424
c = parserState.userQuery[parserState.pos];
410425
if (isStopCharacter(c)) {
411426
foundStopChar = true;
412-
if (c === "," || c === " ") {
427+
if (isSeparatorCharacter(c)) {
413428
parserState.pos += 1;
414429
continue;
415430
} else if (c === "-" || c === ">") {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const QUERY = [
2727
"aaaaa<>b",
2828
"fn:aaaaa<>b",
2929
"->a<>b",
30+
"a<->",
3031
];
3132

3233
const PARSED = [
@@ -282,4 +283,13 @@ const PARSED = [
282283
userQuery: '->a<>b',
283284
error: 'Expected `,` or ` `, found `b`',
284285
},
286+
{
287+
elems: [],
288+
foundElems: 0,
289+
original: 'a<->',
290+
returned: [],
291+
typeFilter: -1,
292+
userQuery: 'a<->',
293+
error: 'Unexpected `-` after `<`',
294+
},
285295
];
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
// ignore-tidy-tab
2+
3+
const QUERY = [
4+
'aaaaaa b',
5+
'a b',
6+
'a,b',
7+
'a\tb',
8+
'a<b c>',
9+
'a<b,c>',
10+
'a<b\tc>',
11+
];
12+
13+
const PARSED = [
14+
{
15+
elems: [
16+
{
17+
name: 'aaaaaa',
18+
fullPath: ['aaaaaa'],
19+
pathWithoutLast: [],
20+
pathLast: 'aaaaaa',
21+
generics: [],
22+
},
23+
{
24+
name: 'b',
25+
fullPath: ['b'],
26+
pathWithoutLast: [],
27+
pathLast: 'b',
28+
generics: [],
29+
},
30+
],
31+
foundElems: 2,
32+
original: "aaaaaa b",
33+
returned: [],
34+
typeFilter: -1,
35+
userQuery: "aaaaaa b",
36+
error: null,
37+
},
38+
{
39+
elems: [
40+
{
41+
name: 'a',
42+
fullPath: ['a'],
43+
pathWithoutLast: [],
44+
pathLast: 'a',
45+
generics: [],
46+
},
47+
{
48+
name: 'b',
49+
fullPath: ['b'],
50+
pathWithoutLast: [],
51+
pathLast: 'b',
52+
generics: [],
53+
},
54+
],
55+
foundElems: 2,
56+
original: "a b",
57+
returned: [],
58+
typeFilter: -1,
59+
userQuery: "a b",
60+
error: null,
61+
},
62+
{
63+
elems: [
64+
{
65+
name: 'a',
66+
fullPath: ['a'],
67+
pathWithoutLast: [],
68+
pathLast: 'a',
69+
generics: [],
70+
},
71+
{
72+
name: 'b',
73+
fullPath: ['b'],
74+
pathWithoutLast: [],
75+
pathLast: 'b',
76+
generics: [],
77+
},
78+
],
79+
foundElems: 2,
80+
original: "a,b",
81+
returned: [],
82+
typeFilter: -1,
83+
userQuery: "a,b",
84+
error: null,
85+
},
86+
{
87+
elems: [
88+
{
89+
name: 'a',
90+
fullPath: ['a'],
91+
pathWithoutLast: [],
92+
pathLast: 'a',
93+
generics: [],
94+
},
95+
{
96+
name: 'b',
97+
fullPath: ['b'],
98+
pathWithoutLast: [],
99+
pathLast: 'b',
100+
generics: [],
101+
},
102+
],
103+
foundElems: 2,
104+
original: "a\tb",
105+
returned: [],
106+
typeFilter: -1,
107+
userQuery: "a\tb",
108+
error: null,
109+
},
110+
{
111+
elems: [
112+
{
113+
name: 'a',
114+
fullPath: ['a'],
115+
pathWithoutLast: [],
116+
pathLast: 'a',
117+
generics: [
118+
{
119+
name: 'b',
120+
fullPath: ['b'],
121+
pathWithoutLast: [],
122+
pathLast: 'b',
123+
generics: [],
124+
},
125+
{
126+
name: 'c',
127+
fullPath: ['c'],
128+
pathWithoutLast: [],
129+
pathLast: 'c',
130+
generics: [],
131+
},
132+
],
133+
},
134+
],
135+
foundElems: 1,
136+
original: "a<b c>",
137+
returned: [],
138+
typeFilter: -1,
139+
userQuery: "a<b c>",
140+
error: null,
141+
},
142+
{
143+
elems: [
144+
{
145+
name: 'a',
146+
fullPath: ['a'],
147+
pathWithoutLast: [],
148+
pathLast: 'a',
149+
generics: [
150+
{
151+
name: 'b',
152+
fullPath: ['b'],
153+
pathWithoutLast: [],
154+
pathLast: 'b',
155+
generics: [],
156+
},
157+
{
158+
name: 'c',
159+
fullPath: ['c'],
160+
pathWithoutLast: [],
161+
pathLast: 'c',
162+
generics: [],
163+
},
164+
],
165+
},
166+
],
167+
foundElems: 1,
168+
original: "a<b,c>",
169+
returned: [],
170+
typeFilter: -1,
171+
userQuery: "a<b,c>",
172+
error: null,
173+
},
174+
{
175+
elems: [
176+
{
177+
name: 'a',
178+
fullPath: ['a'],
179+
pathWithoutLast: [],
180+
pathLast: 'a',
181+
generics: [
182+
{
183+
name: 'b',
184+
fullPath: ['b'],
185+
pathWithoutLast: [],
186+
pathLast: 'b',
187+
generics: [],
188+
},
189+
{
190+
name: 'c',
191+
fullPath: ['c'],
192+
pathWithoutLast: [],
193+
pathLast: 'c',
194+
generics: [],
195+
},
196+
],
197+
},
198+
],
199+
foundElems: 1,
200+
original: "a<b\tc>",
201+
returned: [],
202+
typeFilter: -1,
203+
userQuery: "a<b\tc>",
204+
error: null,
205+
},
206+
];

src/tools/rustdoc-js/tester.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function loadSearchJsAndIndex(searchJs, searchIndex, storageJs, crate) {
275275
"parseInput", "getItemsBefore", "getNextElem", "createQueryElement",
276276
"isReturnArrow", "isPathStart", "getStringElem", "newParsedQuery",
277277
"itemTypeFromName", "isEndCharacter", "isErrorCharacter",
278-
"isIdentCharacter"];
278+
"isIdentCharacter", "isSeparatorCharacter"];
279279

280280
const functions = ["hasOwnPropertyRustdoc", "onEach"];
281281
ALIASES = {};

0 commit comments

Comments
 (0)