String.IndexOf comparisons to -1 return incorrect results

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      This issue was found running the EF provider spec tests--see EF-224

      C# driver only repro:

      var client = new MongoClient("mongodb://localhost:27017");
      
      var database = client.GetDatabase("db224");
      database.DropCollection("customers");
      
      var collection = database.GetCollection<Customer>("customers");
      collection.InsertMany([
          new() { Id = 1, City = "London", Country = "UK" },
          new() { Id = 2, City = "London", Country = "USA" },
          new() { Id = 3, City = "Seattle", Country = "UK" },
          new() { Id = 4, City = "Seattle", Country = "USA" }
      ]);
      
      var results = collection.AsQueryable()
          .Where(c => c.City.IndexOf("e") != -1)
          .ToList();
      
      foreach (var result in results)
      {
          Console.WriteLine($"Found {result} {result.City} {result.Country}");
      }
      
      public class Customer
      {
          public int Id { get; set; }
          public string City { get; set; }
          public string Country { get; set; }
      }
      

            Assignee:
            Robert Stam
            Reporter:
            Arthur Vickers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: