[CSHARP-4789] MongoUrlBuilder builds urls with invalid query string format Created: 15/Sep/23  Updated: 03/Oct/23  Resolved: 03/Oct/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.21.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Jim Paton Assignee: Adelin Mbida Owona
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Summary

The MongoUrlBuilder creates a query string with incorrect separators - ';' instead of '&'.

Driver version 2.21.0

How to Reproduce

Create a new .NET console app with top-level statements and paste the following:

using System;
using MongoDB.Driver;
using MongoDB.Driver.Core.Configuration;
 
var builder = new MongoUrlBuilder();
 
builder.Scheme = ConnectionStringScheme.MongoDB;
builder.Server = new MongoServerAddress("myserver");
 
builder.Username = "user";
builder.Password = "password";
 
builder.AuthenticationMechanism = "DEFAULT";
builder.AuthenticationSource = "mydatabase";
 
Console.WriteLine(builder.ToMongoUrl()); 

Expected output: 

mongodb://user:password@myserver/?authMechanism=DEFAULT&authSource=mydatabase

Actual output: 

mongodb://user:password@myserver/?authMechanism=DEFAULT;authSource=mydatabase

If I paste the actual output into e.g. Compass, it gives an error indicating that DEFAULT;authSource=mydatabase is not a valid value for authMechanism.

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by Githook User [ 03/Oct/23 ]

Author:

{'name': 'Adelin Owona', 'email': '51498470+adelinowona@users.noreply.github.com', 'username': 'adelinowona'}

Message: CSHARP-4789: MongoUrlBuilder builds urls with invalid query string fo… (#1179)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/fa22217d5fce66d252d3a083a5ef2993be3af008

Comment by James Kovacs [ 18/Sep/23 ]

Hi, jim.paton@computershare.co.uk,

Thank you for letting us know about this issue. According to RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax the query portion of a URI is typically key-value pairs delineated by separators, but it does not specify what those separators are. Historically the W3C has recommended using ampersands and/or semicolons as separators, but has since discouraged the use of semicolons. While the .NET/C# Driver can parse either ampersands or semicolons as separator when reading a URI, MongoUrl.ToString() outputs semicolons - which doesn't play nicely with other tooling such as Compass and our Node.js Driver.

Given that the W3C recommends the use of ampersands as key-value pair separators, we will review our various URL-related classes (notably MongoUrl, MongoUrlBuilder, and ConnectionString) to ensure that the resulting connection strings use ampersands as key-value pair separators.

Please follow this ticket for updates and let us know if you have any additional questions.

Sincerely,
James

Comment by PM Bot [ 15/Sep/23 ]

Hi jim.paton@computershare.co.uk, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:49:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.