Skip to content

RUBY-3482 Disallow comma in authMechanismProperties connection string value - #3086

Merged
comandeo-mongo merged 1 commit into
mongodb:masterfrom
comandeo-mongo:3482-comma-auth-mech-props
Jul 29, 2026
Merged

comandeo-mongo merged 1 commit into
mongodb:masterfrom
comandeo-mongo:3482-comma-auth-mech-props

Conversation

@comandeo-mongo

Copy link
Copy Markdown
Contributor

Handles colons in connection-string key-value option values and disallows commas in authMechanismProperties values, per DRIVERS-2915 / connection-string spec.

Changes

Source:

  • lib/mongo/uri/options_mapper.rb — hash_extractor splits each pair on the first colon only (split(':', 2)), so a value may contain colons (e.g. TOKEN_RESOURCE:mongodb://host). New invalidate_on_error: kwarg: for authMechanismProperties, a comma-broken pair (a value that contained a comma) discards the whole option and logs a warning instead of keeping a partial hash. readPreferenceTags keeps its prior per-pair skip behavior.
  • lib/mongo/client.rb — document that a value containing a comma must be passed via the :auth_mech_properties option, not the connection string.

Tests:

  • spec/spec_tests/data/connection_string/valid-options.yml — colon-in-value case.
  • spec/spec_tests/data/connection_string/valid-warnings.yml — comma-causes-warning case.
  • spec/mongo/uri/options_mapper_spec.rb — updated to the new discard-whole-option behavior; added colon-in-value case.

Fixtures are adapted for Ruby: the driver has no MONGODB-OIDC mechanism, and client.rb downcases auth mechanism property keys, so the OIDC mechanism is dropped and expected keys are lowercased.

Test plan

  • bundle exec rspec spec/spec_tests/connection_string_spec.rb spec/spec_tests/uri_options_spec.rb spec/mongo/uri/options_mapper_spec.rb — 758 examples, 0 failures
  • bundle exec rubocop on all touched files — no offenses
  • Spec-compliance review (connection-string spec, key value pairs section)

Jira: https://jira.mongodb.org/browse/RUBY-3482

… value

Parse key-value pairs (authMechanismProperties, readPreferenceTags) using
the first colon only, so a value may contain colons such as
TOKEN_RESOURCE:mongodb://host.

For authMechanismProperties, a comma-broken pair means the value contained
a comma, which is not allowed in a connection string. Discard the whole
option and warn instead of keeping a partial, misleading hash.
@comandeo-mongo
comandeo-mongo marked this pull request as ready for review July 21, 2026 08:23
@comandeo-mongo
comandeo-mongo requested a review from a team as a code owner July 21, 2026 08:23
@comandeo-mongo
comandeo-mongo requested review from Copilot and jamis July 21, 2026 08:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the Ruby driver’s connection-string parsing to correctly handle colons inside key-value option values while ensuring authMechanismProperties does not accept comma-broken values, in line with the connection-string specification requirements described in RUBY-3482 / DRIVERS-2915.

Changes:

  • Adjust hash_extractor to split key/value pairs on the first colon only (split(':', 2)), allowing colons inside values.
  • Add invalidate_on_error: behavior so malformed pairs in authMechanismProperties cause the entire option to be discarded (with a warning), rather than partially parsed.
  • Extend unified YAML fixtures and Ruby specs to cover colon-in-value parsing and the new comma/warning behavior.

Reviewed changes

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

Show a summary per file
File Description
lib/mongo/uri/options_mapper.rb Updates key-value parsing to allow colons in values and discard invalid authMechanismProperties as a whole.
lib/mongo/client.rb Documents that comma-containing auth mechanism property values must be provided via :auth_mech_properties rather than the URI.
spec/mongo/uri/options_mapper_spec.rb Adds/updates unit coverage for colon-in-value handling and whole-option invalidation behavior.
spec/spec_tests/data/connection_string/valid-options.yml Adds a unified test case validating colon-in-value parsing for authMechanismProperties.
spec/spec_tests/data/connection_string/valid-warnings.yml Adds a unified test case validating warnings when a comma breaks authMechanismProperties.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@comandeo-mongo
comandeo-mongo merged commit 05479b5 into mongodb:master Jul 29, 2026
215 of 218 checks passed
@comandeo-mongo
comandeo-mongo deleted the 3482-comma-auth-mech-props branch July 29, 2026 11:01
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.

3 participants