Move $options validation into Parse Server
This commit is contained in:
@@ -1186,7 +1186,7 @@ describe('Parse.Query testing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
fit("regexes with invalid options fail", function(done) {
|
it("regexes with invalid options fail", function(done) {
|
||||||
var query = new Parse.Query(TestObject);
|
var query = new Parse.Query(TestObject);
|
||||||
query.matches("myString", "FootBall", "some invalid option");
|
query.matches("myString", "FootBall", "some invalid option");
|
||||||
query.find(expectError(Parse.Error.INVALID_QUERY, done));
|
query.find(expectError(Parse.Error.INVALID_QUERY, done));
|
||||||
|
|||||||
@@ -517,13 +517,7 @@ function transformConstraint(constraint, inArray) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '$options':
|
case '$options':
|
||||||
var options = constraint[key];
|
answer[key] = constraint[key];
|
||||||
if (!answer['$regex'] || (typeof options !== 'string')
|
|
||||||
|| !options.match(/^[imxs]+$/)) {
|
|
||||||
throw new Parse.Error(Parse.Error.INVALID_QUERY,
|
|
||||||
'got a bad $options');
|
|
||||||
}
|
|
||||||
answer[key] = options;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '$nearSphere':
|
case '$nearSphere':
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ const validateQuery = query => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(query).forEach(key => {
|
Object.keys(query).forEach(key => {
|
||||||
|
if (query[key].$regex) {
|
||||||
|
if (typeof query[key].$options === 'string') {g
|
||||||
|
if (!query[key].$options.match(/^[imxs]+$/)) {
|
||||||
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Bad $options value for query: ${query[key].$options}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!specialQuerykeys.includes(key) && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
|
if (!specialQuerykeys.includes(key) && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
|
||||||
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${key}`);
|
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${key}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user