Commit 775ea587 authored by Marco Mariani's avatar Marco Mariani

while matching, ignore exceptions thrown by cast_to constructors

parent 30ce96a4
......@@ -4773,8 +4773,17 @@ SimpleQuery.prototype.match = function (item) {
cast_to = this._key_schema.cast_lookup[cast_to];
}
value = cast_to(value);
object_value = cast_to(object_value);
try {
value = cast_to(value);
} catch (e) {
value = undefined;
}
try {
object_value = cast_to(object_value);
} catch (e) {
object_value = undefined;
}
}
} else {
object_value = item[key];
......
......@@ -159,8 +159,17 @@ SimpleQuery.prototype.match = function (item) {
cast_to = this._key_schema.cast_lookup[cast_to];
}
value = cast_to(value);
object_value = cast_to(object_value);
try {
value = cast_to(value);
} catch (e) {
value = undefined;
}
try {
object_value = cast_to(object_value);
} catch (e) {
object_value = undefined;
}
}
} else {
object_value = item[key];
......
......@@ -130,6 +130,10 @@
read_from: 'date',
cast_to: dateCast,
equal_match: sameYear
},
broken: {
read_from: 'date',
cast_to: function () { throw new Error('Broken!'); }
}
};
......@@ -178,6 +182,19 @@
})
);
promise.push(
jIO.QueryFactory.create({
type: 'simple',
key: keys.broken,
value: '2013-02-10'
}).
exec(docList()).
then(function (dl) {
deepEqual(dl.length, 0,
'Constructors that throw exceptions should not break a query, but silently fail comparisons');
})
);
RSVP.all(promise).then(noop).always(start);
});
......
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