3838import java .net .URLDecoder ;
3939import java .nio .charset .StandardCharsets ;
4040import java .util .ArrayList ;
41- import java .util .Arrays ;
4241import java .util .Collections ;
4342import java .util .HashMap ;
4443import java .util .HashSet ;
240239 * mechanism (the default).
241240 * </li>
242241 * <li>{@code authMechanismProperties=PROPERTY_NAME:PROPERTY_VALUE,PROPERTY_NAME2:PROPERTY_VALUE2}: This option allows authentication
243- * mechanism properties to be set on the connection string. Property values must be percent-encoded individually, when
244- * special characters are used, including {@code ,} (comma), {@code =}, {@code +}, {@code &}, and {@code %}. The
245- * entire substring following the {@code =} should not itself be encoded.
242+ * mechanism properties to be set on the connection string.
246243 * </li>
247244 * <li>{@code gssapiServiceName=string}: This option only applies to the GSSAPI mechanism and is used to alter the service name.
248245 * Deprecated, please use {@code authMechanismProperties=SERVICE_NAME:string} instead.
@@ -908,7 +905,6 @@ private MongoCredential createCredentials(final Map<String, List<String>> option
908905 }
909906 }
910907
911-
912908 MongoCredential credential = null ;
913909 if (mechanism != null ) {
914910 credential = createMongoCredentialWithMechanism (mechanism , userName , password , authSource , gssapiServiceName );
@@ -926,9 +922,6 @@ private MongoCredential createCredentials(final Map<String, List<String>> option
926922 }
927923 String key = mechanismPropertyKeyValue [0 ].trim ().toLowerCase ();
928924 String value = mechanismPropertyKeyValue [1 ].trim ();
929- if (decodeValueOfKeyValuePair (credential .getMechanism ())) {
930- value = urldecode (value );
931- }
932925 if (MECHANISM_KEYS_DISALLOWED_IN_CONNECTION_STRING .contains (key )) {
933926 throw new IllegalArgumentException (format ("The connection string contains disallowed mechanism properties. "
934927 + "'%s' must be set on the credential programmatically." , key ));
@@ -944,27 +937,6 @@ private MongoCredential createCredentials(final Map<String, List<String>> option
944937 return credential ;
945938 }
946939
947- private static boolean decodeWholeOptionValue (final boolean isOidc , final String key ) {
948- // The "whole option value" is the entire string following = in an option,
949- // including separators when the value is a list or list of key-values.
950- // This is the original parsing behaviour, but implies that users can
951- // encode separators (much like they might with URL parameters). This
952- // behaviour implies that users cannot encode "key-value" values that
953- // contain a comma, because this will (after this "whole value decoding)
954- // be parsed as a key-value separator, rather than part of a value.
955- return !(isOidc && key .equals ("authmechanismproperties" ));
956- }
957-
958- private static boolean decodeValueOfKeyValuePair (@ Nullable final String mechanismName ) {
959- // Only authMechanismProperties should be individually decoded, and only
960- // when the mechanism is OIDC. These will not have been decoded.
961- return AuthenticationMechanism .MONGODB_OIDC .getMechanismName ().equals (mechanismName );
962- }
963-
964- private static boolean isOidc (final List <String > options ) {
965- return options .contains ("authMechanism=" + AuthenticationMechanism .MONGODB_OIDC .getMechanismName ());
966- }
967-
968940 private MongoCredential createMongoCredentialWithMechanism (final AuthenticationMechanism mechanism , final String userName ,
969941 @ Nullable final char [] password ,
970942 @ Nullable final String authSource ,
@@ -1049,9 +1021,7 @@ private Map<String, List<String>> parseOptions(final String optionsPart) {
10491021 return optionsMap ;
10501022 }
10511023
1052- List <String > options = Arrays .asList (optionsPart .split ("&|;" ));
1053- boolean isOidc = isOidc (options );
1054- for (final String part : options ) {
1024+ for (final String part : optionsPart .split ("&|;" )) {
10551025 if (part .isEmpty ()) {
10561026 continue ;
10571027 }
@@ -1063,10 +1033,7 @@ private Map<String, List<String>> parseOptions(final String optionsPart) {
10631033 if (valueList == null ) {
10641034 valueList = new ArrayList <>(1 );
10651035 }
1066- if (decodeWholeOptionValue (isOidc , key )) {
1067- value = urldecode (value );
1068- }
1069- valueList .add (value );
1036+ valueList .add (urldecode (value ));
10701037 optionsMap .put (key , valueList );
10711038 } else {
10721039 throw new IllegalArgumentException (format ("The connection string contains an invalid option '%s'. "
0 commit comments