Skip to content

Commit

Permalink
clarify handling of key-value pairs and add specification test
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed May 29, 2024
1 parent f513ca3 commit 6c3bbac
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
20 changes: 15 additions & 5 deletions source/connection-string/connection-string-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,24 @@ The values in connection options MUST be URL decoded by the parser. The values c
```

- Key value pairs: A value that represents one or more key and value pairs. Multiple key value pairs are delimited by a
comma (","). The key is everything up to the first colon sign (":") and the value is everything afterwards. Drivers
MUST handle subsequent colon signs (":") within the value, unless otherwise specified in this document.\
If any keys
or values contain a comma (",") they MUST not be provided as part of the connection string, since it would interfere
with parsing. Key value pair example:
comma (","). The key is everything up to the first colon sign (":") and the value is everything afterwards. Reserved
characters such as ':' must be escaped according to [RFC 2396](https://www.rfc-editor.org/rfc/rfc2396)

For example:

```
?readPreferenceTags=dc:ny,rack:1
```

Drivers MUST handle unencoded colon signs (":") within the value. For example:

```
?authMechanismProperties=TOKEN_RESOURCE:mongodb%3A%2F%2F...
```

If any keys or values contain a comma (",") they MUST not be provided as part of the connection string, since it would
interfere with parsing.

Any invalid Values for a given key MUST be ignored and MUST log a WARN level message. For example:

```
Expand Down Expand Up @@ -447,6 +455,8 @@ many languages treat strings as `x-www-form-urlencoded` data by default.

## Changelog

- 2024-05-29: Clarify handling of key-value pairs and add specification test.

- 2024-02-15: Migrated from reStructuredText to Markdown.

- 2016-07-22: In Port section, clarify that zero is not an acceptable port.
Expand Down
2 changes: 0 additions & 2 deletions source/connection-string/tests/invalid-uris.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,3 @@ tests:
hosts: ~
auth: ~
options: ~


19 changes: 19 additions & 0 deletions source/connection-string/tests/valid-options.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions source/connection-string/tests/valid-options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ tests:
auth: ~
options:
tls: true
-
description: Colon in a key value pair
uri: mongodb://example.com?authMechanismProperties=TOKEN_RESOURCE:mongodb%3A%2F%2Ftest-cluster
valid: true
warning: false
hosts:
-
type: hostname
host: example.com
port: ~
auth: ~
options:
authmechanismProperties:
TOKEN_RESOURCE: 'mongodb://test-cluster'

0 comments on commit 6c3bbac

Please sign in to comment.