feat: Add regex option u for unicode support in Parse.Query.matches for MongoDB (#9867)

This commit is contained in:
Manuel
2025-10-03 16:38:41 +02:00
committed by GitHub
parent f755a5df21
commit 7cb962a028
2 changed files with 11 additions and 1 deletions

View File

@@ -2113,6 +2113,16 @@ describe('Parse.Query testing', () => {
.then(done); .then(done);
}); });
it_id('351f57a8-e00a-4da2-887d-6e25c9e359fc')(it)('regex with unicode option', async function () {
const thing = new TestObject();
thing.set('myString', 'hello 世界');
await Parse.Object.saveAll([thing]);
const query = new Parse.Query(TestObject);
query.matches('myString', '世界', 'u');
const results = await query.find();
equal(results.length, 1);
});
it_id('823852f6-1de5-45ba-a2b9-ed952fcc6012')(it)('Use a regex that requires all modifiers', function (done) { it_id('823852f6-1de5-45ba-a2b9-ed952fcc6012')(it)('Use a regex that requires all modifiers', function (done) {
const thing = new TestObject(); const thing = new TestObject();
thing.set('myString', 'PArSe\nCom'); thing.set('myString', 'PArSe\nCom');

View File

@@ -111,7 +111,7 @@ const validateQuery = (
Object.keys(query).forEach(key => { Object.keys(query).forEach(key => {
if (query && query[key] && query[key].$regex) { if (query && query[key] && query[key].$regex) {
if (typeof query[key].$options === 'string') { if (typeof query[key].$options === 'string') {
if (!query[key].$options.match(/^[imxs]+$/)) { if (!query[key].$options.match(/^[imxsu]+$/)) {
throw new Parse.Error( throw new Parse.Error(
Parse.Error.INVALID_QUERY, Parse.Error.INVALID_QUERY,
`Bad $options value for query: ${query[key].$options}` `Bad $options value for query: ${query[key].$options}`