@@ -684,29 +684,30 @@ private ConnectionString BuildResolvedConnectionString(ConnectionStringScheme re
684
684
. AllKeys
685
685
. SelectMany ( key => resolvedOptions
686
686
. GetValues ( key )
687
- . Select ( value => $ "{ key } ={ Uri . EscapeDataString ( value ) } ") ) ) ;
687
+ . Select ( value => $ "{ key } ={ EscapeOptionValue ( key , value ) } ") ) ) ;
688
688
689
689
if ( mergedOptions . Count > 0 )
690
690
{
691
691
connectionString += "?" + string . Join ( "&" , mergedOptions ) ;
692
692
}
693
693
694
694
return new ConnectionString ( connectionString , isResolved : true ) ;
695
+
696
+ string EscapeOptionValue ( string key , string value )
697
+ => string . Equals ( key , "authmechanismproperties" , StringComparison . OrdinalIgnoreCase ) ? value : Uri . EscapeDataString ( value ) ;
698
+
695
699
}
696
700
697
701
private void ExtractScheme ( Match match )
698
702
{
699
703
var schemeGroup = match . Groups [ "scheme" ] ;
700
- if ( schemeGroup . Success )
704
+ if ( schemeGroup . Success && schemeGroup . Value == "mongodb+srv" )
701
705
{
702
- if ( schemeGroup . Value == "mongodb+srv" )
706
+ _scheme = ConnectionStringScheme . MongoDBPlusSrv ;
707
+ if ( ! _tls . HasValue )
703
708
{
704
- _scheme = ConnectionStringScheme . MongoDBPlusSrv ;
705
- if ( ! _tls . HasValue )
706
- {
707
- _tls = true ;
708
- _allOptions . Add ( "tls" , "true" ) ;
709
- }
709
+ _tls = true ;
710
+ _allOptions . Add ( "tls" , "true" ) ;
710
711
}
711
712
}
712
713
}
@@ -761,7 +762,13 @@ private void ExtractOptions(Match match)
761
762
var parts = option . Value . Split ( '=' ) ;
762
763
var name = parts [ 0 ] . Trim ( ) ;
763
764
var value = parts [ 1 ] . Trim ( ) ;
764
- _allOptions . Add ( name , Uri . UnescapeDataString ( value ) ) ;
765
+ // Should not decode authmechanismproperties before splitting by separator.
766
+ if ( ! string . Equals ( name , "authmechanismproperties" , StringComparison . OrdinalIgnoreCase ) )
767
+ {
768
+ value = Uri . UnescapeDataString ( value ) ;
769
+ }
770
+
771
+ _allOptions . Add ( name , value ) ;
765
772
ParseOption ( name , value ) ;
766
773
}
767
774
}
@@ -905,12 +912,6 @@ string ProtectConnectionString(string connectionString)
905
912
906
913
private void ParseOption ( string name , string value )
907
914
{
908
- // Should not decode authmechanismproperties before splitting by separator.
909
- if ( ! string . Equals ( name , "authmechanismproperties" , StringComparison . OrdinalIgnoreCase ) )
910
- {
911
- value = Uri . UnescapeDataString ( value ) ;
912
- }
913
-
914
915
switch ( name . ToLowerInvariant ( ) )
915
916
{
916
917
case "appname" :
0 commit comments