Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3297

JsonScanner.GetNextToken() never returns with incomplete regular expressions

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.12.0
    • Affects Version/s: None
    • Component/s: Json
    • None
    • Environment:
      Windows

      In the following example, jsonReader.ReadBsonType() will never return.

       

      using (var jsonReader = new JsonReader("/"))
      {
          Console.WriteLine("before");            
          jsonReader.ReadBsonType();
          Console.WriteLine("after");
      }
      

       

      The problem resides within JsonScanner.GetRegularExpressionToken() as it doesn't account for a -1 return code from buffer.Read() during the RegularExpressionState.InPattern state. GetRegularExpressionToken() will spin indefinitely without yielding.

      This can be fixed with a single line:

       case RegularExpressionState.InPattern:
          switch (c)
          {
              case '/': state = RegularExpressionState.InOptions; break;
              case '\\': state = RegularExpressionState.InEscapeSequence; break;
              // This is the fix
              case -1: state = RegularExpressionState.Invalid; break;
              default: state = RegularExpressionState.InPattern; break;
          }
          break;
      

      I will be submitting a pull request soon.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            ryan.kyser@gmail.com Ryan Kyser
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: