Commit de9b53e5 authored by Tristan Cavelier's avatar Tristan Cavelier

BACKSLASH query: fix ending backslash in query serialization

We now lose the ending backslash during the serialization
in order to build a valid query string.

Stringifying `{type: "simple", value: "hello\\"}` results :
- before ` "hello\"`, which is an invalid query string ;
- now ` "hello"`, which is ok.
parent b08e246c
......@@ -672,6 +672,10 @@
"Argument 1 is not a search text or a parsable object");
};
function sanitizeQueryValue(value) {
return value.replace(/((?:\\\\)*)\\$/, "$1");
}
function objectToSearchText(query) {
var i = 0,
query_list = null,
......@@ -680,7 +684,8 @@
common_key = "";
if (query.type === "simple") {
return (query.key ? query.key + ": " : "") +
(query.operator || "") + ' "' + query.value + '"';
(query.operator || "") +
' "' + sanitizeQueryValue(query.value) + '"';
}
if (query.type === "complex") {
query_list = query.query_list;
......@@ -711,7 +716,7 @@
for (i = 0; i < query_list.length; i += 1) {
string_list.push(
(query_list[i].operator || "") +
' "' + query_list[i].value + '"'
' "' + sanitizeQueryValue(query_list[i].value) + '"'
);
}
} else {
......
......@@ -359,6 +359,24 @@
"{complex query without operator}.toString()"
);
deepEqual(
jIO.QueryFactory.create({
"type": "simple",
"value": "b\\a"
}).toString(),
" \"b\\a\"",
"{simple query with backslash}.toString()"
);
deepEqual(
jIO.QueryFactory.create({
"type": "simple",
"value": "b\\"
}).toString(),
" \"b\"",
"{simple query ending with backslash}.toString()"
);
});
test('Docs with space, tab, and newline', function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment