Commit 8119f88b authored by Tristan Cavelier's avatar Tristan Cavelier

WIP

parent 332807a0
...@@ -6069,6 +6069,7 @@ var arrayExtend = function () { ...@@ -6069,6 +6069,7 @@ var arrayExtend = function () {
return newlist; return newlist;
}, mkSimpleQuery = function (key, value, operator) { }, mkSimpleQuery = function (key, value, operator) {
//TRISTAN var object = {"type": "simple", "key": key, "value": value.replace(/(?:\\(["\\])|(\\[^"\\]))/g, "$1$2")};
var object = {"type": "simple", "key": key, "value": value}; var object = {"type": "simple", "key": key, "value": value};
if (operator !== undefined) { if (operator !== undefined) {
object.operator = operator; object.operator = operator;
...@@ -6223,9 +6224,11 @@ case 15: ...@@ -6223,9 +6224,11 @@ case 15:
$$[$0].operator = $$[$0-1] ; this.$ = $$[$0]; $$[$0].operator = $$[$0-1] ; this.$ = $$[$0];
break; break;
case 17: case 17:
console.log(17, $$[$0]);
this.$ = mkSimpleQuery('', $$[$0]); this.$ = mkSimpleQuery('', $$[$0]);
break; break;
case 18: case 18:
console.log(18, $$[$0-1]);
this.$ = mkSimpleQuery('', $$[$0-1]); this.$ = mkSimpleQuery('', $$[$0-1]);
break; break;
} }
...@@ -7435,7 +7438,16 @@ return new Parser; ...@@ -7435,7 +7438,16 @@ return new Parser;
return new Query(key_schema); return new Query(key_schema);
} }
if (typeof object === "string") { if (typeof object === "string") {
object = parseStringToObject(object); 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" && if (typeof (object || {}).type === "string" &&
query_class_dict[object.type]) { query_class_dict[object.type]) {
...@@ -7445,6 +7457,20 @@ return new Parser; ...@@ -7445,6 +7457,20 @@ return new Parser;
"Argument 1 is not a search text or a parsable object"); "Argument 1 is not a search text or a parsable object");
}; };
function ensureString(value) {
if (value === undefined) { return "undefined"; }
if (value === null) { return "null"; }
return value.toString();
}
function renderSearchTextValue(value) {
value = ensureString(value);
if (/(?:^[=!><]|[\s":])/.test(value)) {
return '"' + value.replace(/((?:\\\\)*)\\$/, "$1").replace(/"/g, '\\"') + '"';
}
return value;
}
function objectToSearchText(query) { function objectToSearchText(query) {
var i = 0, var i = 0,
query_list = null, query_list = null,
...@@ -7453,7 +7479,8 @@ return new Parser; ...@@ -7453,7 +7479,8 @@ return new Parser;
common_key = ""; common_key = "";
if (query.type === "simple") { if (query.type === "simple") {
return (query.key ? query.key + ": " : "") + return (query.key ? query.key + ": " : "") +
(query.operator || "") + ' "' + query.value + '"'; (query.operator || "") +
' ' + renderSearchTextValue(query.value);
} }
if (query.type === "complex") { if (query.type === "complex") {
query_list = query.query_list; query_list = query.query_list;
...@@ -7484,7 +7511,7 @@ return new Parser; ...@@ -7484,7 +7511,7 @@ return new Parser;
for (i = 0; i < query_list.length; i += 1) { for (i = 0; i < query_list.length; i += 1) {
string_list.push( string_list.push(
(query_list[i].operator || "") + (query_list[i].operator || "") +
' "' + query_list[i].value + '"' ' ' + renderSearchTextValue(query_list[i].value)
); );
} }
} else { } else {
......
...@@ -396,14 +396,25 @@ ...@@ -396,14 +396,25 @@
); );
deepEqual( deepEqual(
jIO.Query.parseStringToObject('"\"a b\""'), jIO.Query.parseStringToObject('"\\"a b\\""'),
{ {
"type": "simple", "type": "simple",
"value": "\"a b\"", "key": "",
"value": '"a b"',
}, },
"parseStringToObject('\"\\\"a b\\\"\"')" "parseStringToObject('\"\\\"a b\\\"\"')"
); );
deepEqual(
jIO.Query.parseStringToObject('a=b'),
{
"type": "simple",
"key": "",
"value": 'a=b',
},
"parseStringToObject('a=b')"
);
deepEqual( deepEqual(
jIO.QueryFactory.create('identifier: "\\"').toJSON(), jIO.QueryFactory.create('identifier: "\\"').toJSON(),
{ {
......
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