Skip to content

Conversation

@tnaum-ms
Copy link
Collaborator

@tnaum-ms tnaum-ms commented Feb 2, 2026

This pull request adds robust handling and documentation for duplicate query parameters in DocumentDB and MongoDB connection strings, ensuring compliance with MongoDB specifications and improving reliability when parsing or normalizing connection strings. The core logic now distinguishes between parameters that allow multiple values (like readPreferenceTags) and those that should only use the last value, and provides utility functions for normalization and duplicate detection.

Enhancements to connection string handling:

  • Added deduplication and normalization logic:

    • Implemented deduplicateQueryParameters, hasDuplicateParameters, and a static normalize method in DocumentDBConnectionString to remove duplicate parameters and ensure only allowed duplicates (e.g., readPreferenceTags) are preserved, following MongoDB spec.
    • Added utility functions normalizeConnectionString and hasDuplicateParameters in connectionStringHelpers.ts for easier use throughout the codebase.
  • Improved testing:

    • Added comprehensive tests in DocumentDBConnectionString.test.ts to verify deduplication, normalization, and duplicate detection logic, including real-world Cosmos DB connection string scenarios and round-trip parsing/serialization.

Documentation and compliance:

  • Added a detailed markdown document (connection-string-parameters.md) explaining which MongoDB connection string parameters can have multiple values, the rationale for deduplication, and references to official specifications.
  • Updated credential scan suppressions to include new test files that use fake credentials.

@tnaum-ms tnaum-ms added this to the 0.7.0 - January 2025 milestone Feb 3, 2026
@tnaum-ms tnaum-ms marked this pull request as ready for review February 3, 2026 08:57
@tnaum-ms tnaum-ms requested a review from a team as a code owner February 3, 2026 08:57
Copilot AI review requested due to automatic review settings February 3, 2026 08:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds deduplication methods for MongoDB connection string query parameters to fix bugs where parameters were doubled during migration or editing operations. The implementation adds new methods to detect and remove duplicate parameters while preserving legitimate multi-value parameters (like readPreferenceTags).

Changes:

  • Adds deduplicateQueryParameters(), hasDuplicateParameters(), and static normalize() methods to DocumentDBConnectionString class
  • Implements a cleanup function cleanupDuplicateConnectionStringParameters() that runs during extension initialization to fix existing corrupted connection strings
  • Changes the post-migration error resolution flow to await critical fixes (folder placeholder strings and duplicate parameters) before proceeding, with orphan cleanup continuing as fire-and-forget
  • Updates v1 to v2 migration to deduplicate connection strings during the migration process

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/documentdb/utils/DocumentDBConnectionString.ts Adds three new methods for detecting and removing duplicate query parameters from connection strings
src/documentdb/utils/DocumentDBConnectionString.test.ts Comprehensive test coverage for deduplication methods including real-world Cosmos DB connection strings with special characters
src/documentdb/utils/connectionStringHelpers.ts Exports helper functions normalizeConnectionString() and hasDuplicateParameters() for public API
src/services/connectionStorageService.ts Implements cleanup function for duplicate parameters, updates initialization flow to await critical fixes, and adds deduplication to v1 migration
src/services/connectionStorageService.test.ts Adds tests for duplicate parameter removal during v1 to v3 migration and real-world Cosmos DB connection string handling
src/services/connectionStorageService.cleanup.test.ts New test file with comprehensive tests for all cleanup functions including deduplication, folder fixes, and orphan cleanup
src/services/connectionStorageService.contract.test.ts Updates test credentials to use more obviously fake values for security scanning
.azure-pipelines/compliance/CredScanSuppressions.json Adds suppressions for new test files containing fake credentials

@tnaum-ms
Copy link
Collaborator Author

tnaum-ms commented Feb 3, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Feb 3, 2026

@tnaum-ms I've opened a new pull request, #481, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Feb 3, 2026

@tnaum-ms I've opened a new pull request, #483, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 4 commits February 3, 2026 11:19
…ion with whitelist

- Created comprehensive documentation (connection-string-parameters.md) explaining which parameters can have multiple values
- Identified readPreferenceTags as the only parameter that allows multiple values per MongoDB spec
- Updated deduplicateQueryParameters() to follow "last value wins" for non-whitelisted parameters
- Added MULTI_VALUE_PARAMETERS whitelist for proper handling
- Added tests verifying correct behavior for both whitelisted and non-whitelisted parameters
- All tests passing (76/76)

Co-authored-by: tnaum-ms <171359267+tnaum-ms@users.noreply.github.com>
Added explanatory comment about case-insensitive matching per MongoDB spec

Co-authored-by: tnaum-ms <171359267+tnaum-ms@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@tnaum-ms tnaum-ms merged commit f248725 into next Feb 3, 2026
14 checks passed
@tnaum-ms tnaum-ms deleted the dev/tnaum/defensive-connection-string-handling-duplicate-parameters branch February 3, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants