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

JsonScanner.GetNextToken() never returns with incomplete regular expressions

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • 2.12.0
    • Json
    • None
    • Windows

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: