Skip to content

Fix database name extraction from DSN containing a CA file path #3381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025

Conversation

fergusean
Copy link
Contributor

@fergusean fergusean commented May 13, 2025

When a DSN contains a path to a CA file for TLS, the database name is improperly extracted.

Sample:

$dsn = 'mongodb://db_admin:[email protected]:27017/mydb?tls=true&tlsCAFile=/usr/share/pki/ca-trust-source/anchors/aws-rds-bundle.pem&retryWrites=false';
echo $connection->getDefaultDatabaseName($dsn, []);

Before:

aws-rds-bundle.pem

After:

mydb

Checklist

  • Add tests and ensure they pass

@fergusean fergusean requested a review from a team as a code owner May 13, 2025 20:03
@fergusean fergusean requested a review from GromNaN May 13, 2025 20:03
@GromNaN GromNaN added the bug label May 13, 2025
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @fergusean, thank you for submitting this PR and contributing to the project.

Could you add a unit test to validate there is no regression?
You can add a case in ConnectionTest::dataConnectionConfig()

@fergusean
Copy link
Contributor Author

@GromNaN done!

@fergusean fergusean requested a review from GromNaN May 15, 2025 03:40
@GromNaN GromNaN changed the title non-greedy regex for database name extraction Fix database name extraction from DSN containing a CA file path May 19, 2025
@GromNaN GromNaN merged commit 6260b47 into mongodb:5.x May 19, 2025
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants