Skip to content

Commit f796d69

Browse files
committed
Move $options validation into Parse Server
1 parent 452b737 commit f796d69

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

spec/ParseQuery.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ describe('Parse.Query testing', () => {
11861186
});
11871187
});
11881188

1189-
fit("regexes with invalid options fail", function(done) {
1189+
it("regexes with invalid options fail", function(done) {
11901190
var query = new Parse.Query(TestObject);
11911191
query.matches("myString", "FootBall", "some invalid option");
11921192
query.find(expectError(Parse.Error.INVALID_QUERY, done));

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,7 @@ function transformConstraint(constraint, inArray) {
517517
break;
518518

519519
case '$options':
520-
var options = constraint[key];
521-
if (!answer['$regex'] || (typeof options !== 'string')
522-
|| !options.match(/^[imxs]+$/)) {
523-
throw new Parse.Error(Parse.Error.INVALID_QUERY,
524-
'got a bad $options');
525-
}
526-
answer[key] = options;
520+
answer[key] = constraint[key];
527521
break;
528522

529523
case '$nearSphere':

src/Controllers/DatabaseController.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ const validateQuery = query => {
6767
}
6868

6969
Object.keys(query).forEach(key => {
70+
if (query[key].$regex) {
71+
if (typeof query[key].$options === 'string') {g
72+
if (!query[key].$options.match(/^[imxs]+$/)) {
73+
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Bad $options value for query: ${query[key].$options}`);
74+
}
75+
}
76+
}
7077
if (!specialQuerykeys.includes(key) && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
7178
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${key}`);
7279
}

0 commit comments

Comments
 (0)