Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix: escapeCql handles invalid date objects

tests: adds tests for timestamps
  • Loading branch information...
commit 49fe68043285def3ca9fd217f1463c842e3b0ae0 1 parent bab0a38
@tim-dev tim-dev authored
Showing with 27 additions and 1 deletion.
  1. +5 −1 lib/connection.js
  2. +17 −0 test/cql3.js
  3. +5 −0 test/helpers/cql3.json
View
6 lib/connection.js
@@ -103,7 +103,11 @@ function escapeCQL(val) {
}
if(val instanceof Date){
- return val.getTime();
+ val = val.getTime();
+ if(isNaN(val)){
+ throw errors.create(new Error('Invalid Date'));
+ }
+ return val;
}
if(typeof val === 'number' || typeof val === 'boolean'){
View
17 test/cql3.js
@@ -67,6 +67,14 @@ function testResultless(){
return testCql.apply(testCql, args);
}
+function makeDates(dates_array){
+ var ret = [], i = 0, len = dates_array.length;
+ for(i;i<len;i++){
+ ret.push(new Date(dates_array[i]));
+ }
+ return ret;
+}
+
module.exports = {
'setUp':function(test, assert){
Helenus = require('helenus');
@@ -293,6 +301,15 @@ module.exports = {
assert.strictEqual(res[0].get('varnumber').value, -8388607);//test a 3 byte-long variable integer
}),
+ 'test cql timestamp create table':testResultless(config['timestamp_create']),
+ 'test cql timestamp update':testResultless(config['timestamp_update#cql'], makeDates(config['timestamp_update#vals'])),
+ 'test cql timestamp invalid date': function(test, assert) {
+ assert.throws(function(){
+ conn.cql(config['timestamp_invalid#cql'], makeDates(config['timestamp_invalid#vals']))
+ }, Error)
+ test.finish();
+ },
+
'test cql drop keyspace':testResultless(config['drop_ks#cql']),
'tearDown':function(test, assert){
View
5 test/helpers/cql3.json
@@ -51,6 +51,11 @@
"integers_select2#cql" : "SELECT * FROM integers where number = -1",
"integers_select3#cql" : "SELECT * FROM integers where number = -2",
+ "timestamp_create" : "CREATE TABLE timestamps (old timestamp, current timestamp, future timestamp, PRIMARY KEY (old))",
+ "timestamp_update#cql" : "UPDATE timestamps SET current = ?, future = ? WHERE old = ?",
+ "timestamp_update#vals" : [null, "2100-01-01", "1969-07-20"],
+ "timestamp_invalid#cql" : "UPDATE timestamps SET current = ? WHERE old = ?",
+ "timestamp_invalid#vals" : [null, "THIS ISNT A DATE"],
"prepare#cql" : "SELECT * FROM ? WHERE KEY = ?",
"error#cql" : "SOME INVALID CQL"
Please sign in to comment.
Something went wrong with that request. Please try again.