Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-12600

Failure to parse $regex $option 'x' in fromjson()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.3
    • Component/s: Shell
    • ALL
    • Hide

      Run the following dbtest:

          // Base client helper
          struct ClientBase {
              ClientBase() { mongo::lastError.reset(new LastError()); }
              virtual ~ClientBase() { }
      
          protected:
              static bool error() {
                  return !_client.getPrevError().getField( "err" ).isNull();
              }
              static DBDirectClient _client;
          };
          DBDirectClient ClientBase::_client;
      
          // Runner for generated queries
          template <typename Q>
          struct GeneratedQueryRunner : ClientBase {
              virtual void run(){
                  auto_ptr<DBClientCursor> cursor = _client.query(kNameSpace, Q::getQuery(), 0);
                  ASSERT(!error());
      
                  int docCount = 0;
                  BSONObj result;
                  while (cursor->more()) {
                      ++docCount;
                      result = cursor->next().getOwned();
                  }
                  LOG(0) << "Document Count: " << docCount;
              }
          };
      
      struct GeneratedQuery19 {
            static BSONObj getQuery() { return query; }
            static BSONObj* getProjection() { return NULL; }
            static BSONObj query;
        };
      BSONObj GeneratedQuery19::query = fromjson("{\"d\":{\"$regex\":\"(s|t|y|n)\\..\",\"$options\":'mxisi'}}");
      
      ...
      
          class All : public Suite {
          public:
              All() : Suite( "GeneratedQueries" ) { }
              void setupTests() {
                  add< GeneratedQueryRunner<GeneratedQuery19> >();
              }
          } myall;
      

      Eventually this should included as part of the fuzz/nltk generated tests.

      Show
      Run the following dbtest: // Base client helper struct ClientBase { ClientBase() { mongo::lastError.reset( new LastError()); } virtual ~ClientBase() { } protected : static bool error() { return !_client.getPrevError().getField( "err" ).isNull(); } static DBDirectClient _client; }; DBDirectClient ClientBase::_client; // Runner for generated queries template <typename Q> struct GeneratedQueryRunner : ClientBase { virtual void run(){ auto_ptr<DBClientCursor> cursor = _client.query(kNameSpace, Q::getQuery(), 0); ASSERT(!error()); int docCount = 0; BSONObj result; while (cursor->more()) { ++docCount; result = cursor->next().getOwned(); } LOG(0) << "Document Count: " << docCount; } }; struct GeneratedQuery19 { static BSONObj getQuery() { return query; } static BSONObj* getProjection() { return NULL; } static BSONObj query; }; BSONObj GeneratedQuery19::query = fromjson( "{\" d\ ":{\" $regex\ ":\" (s|t|y|n)\\..\ ",\" $options\ ": 'mxisi' }}" ); ... class All : public Suite { public : All() : Suite( "GeneratedQueries" ) { } void setupTests() { add< GeneratedQueryRunner<GeneratedQuery19> >(); } } myall; Eventually this should included as part of the fuzz/nltk generated tests.

      The following query throws a FailedToParse exception when passed to fromjson():

      {"d":{"$regex":"(s|t|y|n)\..","$options":'mxsi'}}
      
      libc++abi.dylib: terminating with uncaught exception of type mongo::MsgAssertionException: code FailedToParse: FailedToParse: Bad regex option: x: offset:47 of:{"d":{"$regex":"(s|t|y|n)\..","$options":'mxsi'}}
      

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            benjamin.becker Ben Becker
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: