Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2977

Query parameters with path in connection string not working on windows

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0.0, 3.6.4
    • Affects Version/s: 3.6.3
    • Component/s: Shell
    • None

      Problem Description

      Some of the query parameters in a connection string allow a file path to be specified, e.g. the tlsCAFile option, that will be resolved to the file contents before connecting. However, using an absolute path on Windows will result in an error:

      TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Object

      It seems that the error is caused by the parseQueryStringItemValue method (https://github.com/mongodb/node-mongodb-native/blob/master/src/connection_string.ts#L154). It checks for the presence of a : in the parameter value and if so converts it into an object with key-values by splitting. However, an absolute path on windows will always start with <drive letter>:\... so the : will always be present.

      This at least affects v4 - not tested for 3.x.

      Steps to Reproduce

      Try connecting to a MongoDB node passing the tlsCAFile query parameter in the connection string on Windows with a valid absolute path.

      Expected Results

      The connection is created and works/fails according to the CA provided.

      Actual Results

      No connection is created but an error is thrown while trying to execute fs.readFileSync when resolving the tlsCAFile.

            Assignee:
            eric.adum@mongodb.com Eric Adum (Inactive)
            Reporter:
            michael.rose@mongodb.com Michael Rose (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: