Fix some corner cases
This commit is contained in:
parent
da363b2fc9
commit
d7d538a8c4
@ -176,11 +176,14 @@ window.initSearch = function(rawSearchIndex) {
|
||||
throw new Error("Cannot use literal search when there is more than one element");
|
||||
}
|
||||
parserState.pos += 1;
|
||||
var start = parserState.pos;
|
||||
var end = getIdentEndPosition(parserState);
|
||||
if (parserState.pos >= parserState.length) {
|
||||
throw new Error("Unclosed `\"`");
|
||||
} else if (parserState.userQuery[end] !== "\"") {
|
||||
throw new Error(`Unexpected \`${parserState.userQuery[end]}\` in a string element`);
|
||||
} else if (start === end) {
|
||||
throw new Error("Cannot have empty string element");
|
||||
}
|
||||
// To skip the quote at the end.
|
||||
parserState.pos += 1;
|
||||
@ -657,11 +660,6 @@ window.initSearch = function(rawSearchIndex) {
|
||||
query.literalSearch = parserState.totalElems > 1;
|
||||
}
|
||||
query.foundElems = query.elems.length + query.returned.length;
|
||||
if (query.foundElems === 0 && parserState.length !== 0) {
|
||||
// In this case, we'll simply keep whatever was entered by the user...
|
||||
query.elems.push(createQueryElement(query, parserState, userQuery, [], false));
|
||||
query.foundElems += 1;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ const QUERY = [
|
||||
'"a" -> "p"',
|
||||
'->"-"',
|
||||
'"a',
|
||||
'""',
|
||||
];
|
||||
|
||||
const PARSED = [
|
||||
@ -74,4 +75,13 @@ const PARSED = [
|
||||
userQuery: '"a',
|
||||
error: 'Unclosed `"`',
|
||||
},
|
||||
{
|
||||
elems: [],
|
||||
foundElems: 0,
|
||||
original: '""',
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: '""',
|
||||
error: 'Cannot have empty string element',
|
||||
},
|
||||
];
|
||||
|
@ -1,7 +1,13 @@
|
||||
// This test is mostly to check that the parser still kinda outputs something
|
||||
// (and doesn't enter an infinite loop!) even though the query is completely
|
||||
// invalid.
|
||||
const QUERY = ['a b', 'a b', 'a,b(c)', 'aaa,a'];
|
||||
const QUERY = [
|
||||
'a b',
|
||||
'a b',
|
||||
'a,b(c)',
|
||||
'aaa,a',
|
||||
',,,,',
|
||||
];
|
||||
|
||||
const PARSED = [
|
||||
{
|
||||
@ -85,4 +91,13 @@ const PARSED = [
|
||||
userQuery: "aaa,a",
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
elems: [],
|
||||
foundElems: 0,
|
||||
original: ",,,,",
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: ",,,,",
|
||||
error: null,
|
||||
},
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user