Commit 21e0295d authored by Tristan Cavelier's avatar Tristan Cavelier

query: turn invalid query string into valid simple query value

Parsing `title: "hello\"` results :
- before `Parse error on line 1: Expecting 'QUOTE', got '1'`
- now `{ type: simple, key: undefined, value: 'title: "hello\\"' }`
parent d08b150f
......@@ -662,7 +662,16 @@
return new Query(key_schema);
}
if (typeof object === "string") {
try {
object = parseStringToObject(object);
} catch (error) {
if (error.hash && error.hash.expected &&
error.hash.expected.length === 1 &&
error.hash.expected[0] === "'QUOTE'") {
return new query_class_dict.simple({value: object});
}
throw error;
}
}
if (typeof (object || {}).type === "string" &&
query_class_dict[object.type]) {
......
......@@ -377,6 +377,22 @@
"{simple query ending with backslash}.toString()"
);
deepEqual(
jIO.QueryFactory.create('identifier: "\\"').toJSON(),
{
"key": undefined, // could not exist as JSON.stringify removes it
"type": "simple",
"value": 'identifier: "\\"',
},
"'identifier: \"\\\"'.toJSON()"
);
deepEqual(
jIO.QueryFactory.create('identifier: "\\"').toString(),
' "identifier: "\\""',
"'identifier: \"\\\"'.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