Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

topTerm lastSeen keys clash with Query.prototype.{select,values,sort,…

…limit} --> moved to topTerm.cache hash

fixed tests; fixed null dereference in encodeValue
  • Loading branch information...
commit 9fd7aa4a838f23312f9373af91888c6c93b4ea9c 1 parent e561ab6
@dvv dvv authored
Showing with 12 additions and 6 deletions.
  1. +4 −3 lib/parser.js
  2. +1 −0  lib/query.js
  3. +7 −3 tests/query.js
View
7 lib/parser.js
@@ -24,6 +24,7 @@ function parse(/*String|Object*/query, parameters){
query = '';
var term = new exports.Query();
var topTerm = term;
+ topTerm.cache = {}; // room for lastSeen params
if(typeof query === "object"){
if(query instanceof exports.Query){
return query;
@@ -92,13 +93,13 @@ function parse(/*String|Object*/query, parameters){
// cache the last seen sort(), select(), values() and limit()
if (exports.lastSeen.indexOf(term.name) >= 0) {
- topTerm[term.name] = term.args;
+ topTerm.cache[term.name] = term.args;
}
// cache the last seen id equality
if (term.name === 'eq' && term.args[0] === exports.primaryKeyName) {
var id = term.args[1];
if (id && !(id instanceof RegExp)) id = id.toString();
- topTerm[exports.primaryKeyName] = id;
+ topTerm.cache[exports.primaryKeyName] = id;
}
}
return "";
@@ -116,7 +117,7 @@ function parse(/*String|Object*/query, parameters){
term = newTerm;
// cache the last seen sort(), select(), values() and limit()
if (exports.lastSeen.indexOf(term.name) >= 0) {
- topTerm[term.name] = term.args;
+ topTerm.cache[term.name] = term.args;
}
}
function setConjunction(operator){
View
1  lib/query.js
@@ -74,6 +74,7 @@ function encodeString(s) {
exports.encodeValue = function(val) {
var encoded;
+ if (val === null) val = 'null';
if (val !== parser.converters["default"]('' + (
val.toISOString && val.toISOString() || val.toString()
))) {
View
10 tests/query.js
@@ -29,7 +29,7 @@ var queryPairs = {
],
"dot-comparison": [
{"foo.bar=3": {name:"and", args:[{name:"eq", args:["foo.bar",3]}]}},
- {"select(sub.name)": {name:"and", args:[{name:"select", args:["sub.name"]}], select: ["sub.name"]}}
+ {"select(sub.name)": {name:"and", args:[{name:"select", args:["sub.name"]}], cache: {select: ["sub.name"]}}}
],
"equality": [
{"eq(a,b)": {name:"and", args:[{name:"eq", args:["a","b"]}]}},
@@ -128,9 +128,13 @@ exports.testParsing = function() {
var key = Object.keys(pair)[0];
try{
var parsed = parseQuery(key);
+ if (!Object.keys(parsed.cache).length)
+ delete parsed.cache;
var result = pair[key];
if(typeof result == "string"){
result = parseQuery(result);
+ if (!Object.keys(result.cache).length)
+ delete result.cache;
}
}catch(e){
e.message += " parsing " + group + ": " + key;
@@ -150,9 +154,9 @@ exports.testBindParameters = function() {
// TODO
var parsed;
parsed = parseQuery('in(id,$1)', [['a','b','c']]);
- assert.deepEqual(parsed, {name: 'and', args: [{name: 'in', args: ['id', ['a', 'b', 'c']]}]});
+ assert.deepEqual(parsed, {name: 'and', args: [{name: 'in', args: ['id', ['a', 'b', 'c']]}], cache: {}});
parsed = parseQuery('eq(id,$1)', ['a']);
- assert.deepEqual(parsed, {name: 'and', args: [{name: 'eq', args: ['id', 'a']}], id: 'a'});
+ assert.deepEqual(parsed, {name: 'and', args: [{name: 'eq', args: ['id', 'a']}], cache: {id: 'a'}});
};
exports.testExecution = function() {
Please sign in to comment.
Something went wrong with that request. Please try again.