[CSHARP-3876] Fix surrogate pair handling in CStringUtf8Encoding Created: 23/Sep/21  Updated: 28/Oct/23  Resolved: 29/Sep/21

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.13.1
Fix Version/s: 2.13.2

Type: Bug Priority: Major - P3
Reporter: Air A Assignee: Dmitry Lukyanov (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We are trying to use the following to search a text using Regex. Here is our code:

 

string name = "jm😋"

var queryExpr = new BsonRegularExpression(name);
var filter = Builders<CurrentClass>.Filter.Regex(s => s.Name, queryExpr);

 

Upon running this one, we will received an error showing: 
Regular expression is invalid: invalid UTF-8 string

 

We try to inspect the query that is being generated from that filter, and surprisingly it doesn't use the $regex syntax. Here is the generated query:
find({ "Name" : /jm😋/ })

 

 

We are expecting the $regex syntax like this one: 
find({ "Name" :

{ "$regex" : "jm\ud83d\ude0b" }

})

 

This is a serious bug on the Regex Filter Builder on the c# Library. Is there a way to use the $regex filter in the Filter Builder strongly type? We want to avoid creating BSON document as possible since it is not strongly typed.

 

Using latest version of the c# Library: 2.13.1



 Comments   
Comment by Githook User [ 06/Oct/21 ]

Author:

{'name': 'Dmitry Lukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}

Message: CSHARP-3876: Builders<T>.Filter.Regex(s => s.Name, keyword) doesn't work. (#628)

CSHARP-3876: Builders<T>.Filter.Regex(s => s.Name, keyword) Doesn't Work.
Branch: v2.13.x
https://github.com/mongodb/mongo-csharp-driver/commit/2932d77d040ff78e895d4281d8a6198ec5d2d06e

Comment by Dmitry Lukyanov (Inactive) [ 29/Sep/21 ]

airwyntin@investagrams.com, most-likely the next patch release will be available next week

Comment by Githook User [ 29/Sep/21 ]

Author:

{'name': 'Dmitry Lukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}

Message: CSHARP-3876: Builders<T>.Filter.Regex(s => s.Name, keyword) doesn't work. (#628)

CSHARP-3876: Builders<T>.Filter.Regex(s => s.Name, keyword) Doesn't Work.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/3480e7219d2f4870d4deca87fae01691befbbc1f

Comment by Air A [ 24/Sep/21 ]

Thanks @dmitry lukyanov 

 

Looking forward to that fix. This is somehow blocker for us since we can't search it properly. Do you have an estimate timeline on when will the next version be release? 

Comment by Dmitry Lukyanov (Inactive) [ 23/Sep/21 ]

Thanks airwyntin@investagrams.com ,

thanks for your report, I can confirm that this is a bug, we will fix it and include in the next release.

 

Comment by Air A [ 23/Sep/21 ]

This happens to emoji texts, Please use our sample text keyword: jm😋 to reproduce the bug

Generated at Wed Feb 07 21:46:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.