parse-key/lex incorrectly matches a single `:` as a cast
A bug was introduced in 6.5 when allowing for column references on the rhs of the criteria. In my use case, values start with text that also match a column name. The value also includes a :
which the lex method is treating as a cast even though it's not ::
.
Steps to reproduce
- Create table
A
with columns [a_id
,foo
] - Create table
B
with columns [b_id
,bar
] - Execute a find on a join between
A
andB
.
join({...}).find({
foo: "foo:1234:abc"
})
Result
Invalid SQL result: ...WHERE "A"."foo" = "A"."foo"::1234abc
Potential Fix
Update parse-key.js lex method. Replace the case statement for ':' with
case ':':
// cast; new token, but we ignore the : characters since we only care
// about type
if (_.last(buffer) === ':') {
buffer.pop();
if (!hasCast) {
hasCast = true;
jsonAsText = true; // Explicit casts must use as-text operators
buffer = tokens[tokens.push([]) - 1];
}
} else {
buffer.push(char);
}
break;