mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-01-13 17:03:01 +08:00
Merge pull request #270 from letsface/fix-number-to-string
When query is number but property is string convert back to string
This commit is contained in:
@@ -123,6 +123,8 @@ Collection.prototype.sanitize = function (body) {
|
||||
sanitized[key] = val;
|
||||
} else if(expected == 'number' && actual == 'string') {
|
||||
sanitized[key] = parseFloat(val);
|
||||
} else if(expected == 'string' && actual == 'number') {
|
||||
sanitized[key] = '' + val;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -147,7 +149,9 @@ Collection.prototype.sanitizeQuery = function (query) {
|
||||
if (key === '$limitRecursion') return;
|
||||
if (key === '$skipEvents') return;
|
||||
|
||||
if(expected == 'number' && actual == 'string') {
|
||||
if(expected == 'string' && actual == 'number') {
|
||||
sanitized[key] = '' + val;
|
||||
} else if(expected == 'number' && actual == 'string') {
|
||||
sanitized[key] = parseFloat(val);
|
||||
} else if(expected == 'boolean' && actual != 'boolean') {
|
||||
sanitized[key] = (val === 'true') ? true : false;
|
||||
|
||||
@@ -81,8 +81,32 @@ describe('collection', function(){
|
||||
var sanitized = r.sanitize({age: '22'});
|
||||
expect(sanitized.age).to.equal(22);
|
||||
});
|
||||
|
||||
it('should convert number to strings', function() {
|
||||
var r = createCollection({
|
||||
token: {
|
||||
type: 'string'
|
||||
}
|
||||
});
|
||||
|
||||
var sanitized = r.sanitize({token: 123456});
|
||||
expect(sanitized.token).to.equal('123456');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.sanitizeQuery(query)', function(){
|
||||
it('should convert number to strings', function() {
|
||||
var r = createCollection({
|
||||
token: {
|
||||
type: 'string'
|
||||
}
|
||||
});
|
||||
|
||||
var sanitized = r.sanitizeQuery({token: 123456});
|
||||
expect(sanitized.token).to.equal('123456');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.handle(ctx)', function(){
|
||||
it('should have a store', function() {
|
||||
var c = new Collection('foo', { db: db.create(TEST_DB) });
|
||||
|
||||
Reference in New Issue
Block a user