@@ -176,13 +176,11 @@ window.initSearch = function(rawSearchIndex) {
176
176
throw new Error ( "Cannot use literal search when there is more than one element" ) ;
177
177
}
178
178
parserState . pos += 1 ;
179
- while ( parserState . pos < parserState . length &&
180
- parserState . userQuery [ parserState . pos ] !== "\"" )
181
- {
182
- parserState . pos += 1 ;
183
- }
179
+ var end = getIdentEndPosition ( parserState ) ;
184
180
if ( parserState . pos >= parserState . length ) {
185
181
throw new Error ( "Unclosed `\"`" ) ;
182
+ } else if ( parserState . userQuery [ end ] !== "\"" ) {
183
+ throw new Error ( `Unexpected \`${ parserState . userQuery [ end ] } \` in a string element` ) ;
186
184
}
187
185
// To skip the quote at the end.
188
186
parserState . pos += 1 ;
@@ -284,6 +282,45 @@ window.initSearch = function(rawSearchIndex) {
284
282
} ;
285
283
}
286
284
285
+ /**
286
+ * This function goes through all characters until it reaches an invalid ident character or the
287
+ * end of the query. It returns the position of the last character of the ident.
288
+ *
289
+ * @param {ParserState } parserState
290
+ *
291
+ * @return {integer }
292
+ */
293
+ function getIdentEndPosition ( parserState ) {
294
+ var end = parserState . pos ;
295
+ while ( parserState . pos < parserState . length ) {
296
+ var c = parserState . userQuery [ parserState . pos ] ;
297
+ if ( ! isIdentCharacter ( c ) ) {
298
+ if ( isErrorCharacter ( c ) ) {
299
+ throw new Error ( `Unexpected \`${ c } \`` ) ;
300
+ } else if (
301
+ isStopCharacter ( c ) ||
302
+ isSpecialStartCharacter ( c ) ||
303
+ isSeparatorCharacter ( c ) )
304
+ {
305
+ break ;
306
+ }
307
+ // If we allow paths ("str::string" for example).
308
+ else if ( c === ":" ) {
309
+ if ( ! isPathStart ( parserState ) ) {
310
+ break ;
311
+ }
312
+ // Skip current ":".
313
+ parserState . pos += 1 ;
314
+ } else {
315
+ throw new Error ( `Unexpected \`${ c } \`` ) ;
316
+ }
317
+ }
318
+ parserState . pos += 1 ;
319
+ end = parserState . pos ;
320
+ }
321
+ return end ;
322
+ }
323
+
287
324
/**
288
325
* @param {ParsedQuery } query
289
326
* @param {ParserState } parserState
@@ -294,39 +331,14 @@ window.initSearch = function(rawSearchIndex) {
294
331
var generics = [ ] ;
295
332
296
333
var start = parserState . pos ;
297
- var end = start ;
334
+ var end ;
298
335
// We handle the strings on their own mostly to make code easier to follow.
299
336
if ( parserState . userQuery [ parserState . pos ] === "\"" ) {
300
337
start += 1 ;
301
338
getStringElem ( query , parserState , isInGenerics ) ;
302
339
end = parserState . pos - 1 ;
303
340
} else {
304
- while ( parserState . pos < parserState . length ) {
305
- var c = parserState . userQuery [ parserState . pos ] ;
306
- if ( ! isIdentCharacter ( c ) ) {
307
- if ( isErrorCharacter ( c ) ) {
308
- throw new Error ( `Unexpected \`${ c } \`` ) ;
309
- } else if (
310
- isStopCharacter ( c ) ||
311
- isSpecialStartCharacter ( c ) ||
312
- isSeparatorCharacter ( c ) )
313
- {
314
- break ;
315
- }
316
- // If we allow paths ("str::string" for example).
317
- else if ( c === ":" ) {
318
- if ( ! isPathStart ( parserState ) ) {
319
- break ;
320
- }
321
- // Skip current ":".
322
- parserState . pos += 1 ;
323
- } else {
324
- throw new Error ( `Unexpected \`${ c } \`` ) ;
325
- }
326
- }
327
- parserState . pos += 1 ;
328
- end = parserState . pos ;
329
- }
341
+ end = getIdentEndPosition ( parserState ) ;
330
342
}
331
343
if ( parserState . pos < parserState . length &&
332
344
parserState . userQuery [ parserState . pos ] === "<" )
0 commit comments