@@ -556,9 +556,7 @@ public string GetOption(string name)
556556 }
557557
558558 var txtRecords = _dnsResolver . ResolveTxtRecords ( host , cancellationToken ) ;
559- var options = GetOptionsFromTxtRecords ( txtRecords ) ;
560-
561- var resolvedOptions = GetResolvedOptions ( options ) ;
559+ var resolvedOptions = GetResolvedOptionsFromTxtRecords ( txtRecords ) ;
562560
563561 return BuildResolvedConnectionString ( resolvedScheme , hosts , resolvedOptions ) ;
564562 }
@@ -606,9 +604,7 @@ public string GetOption(string name)
606604 }
607605
608606 var txtRecords = await _dnsResolver . ResolveTxtRecordsAsync ( host , cancellationToken ) . ConfigureAwait ( false ) ;
609- var options = GetOptionsFromTxtRecords ( txtRecords ) ;
610-
611- var resolvedOptions = GetResolvedOptions ( options ) ;
607+ var resolvedOptions = GetResolvedOptionsFromTxtRecords ( txtRecords ) ;
612608
613609 return BuildResolvedConnectionString ( resolvedScheme , hosts , resolvedOptions ) ;
614610 }
@@ -655,9 +651,9 @@ private ConnectionString BuildResolvedConnectionString(ConnectionStringScheme re
655651 mergedOptions . AddRange (
656652 resolvedOptions
657653 . AllKeys
658- . SelectMany ( x => resolvedOptions
659- . GetValues ( x )
660- . Select ( y => $ "{ x } ={ Uri . EscapeDataString ( y ) } ") ) ) ;
654+ . SelectMany ( key => resolvedOptions
655+ . GetValues ( key )
656+ . Select ( value => $ "{ key } ={ Uri . EscapeDataString ( value ) } ") ) ) ;
661657
662658 if ( mergedOptions . Count > 0 )
663659 {
@@ -732,8 +728,10 @@ private void ExtractOptions(Match match)
732728 foreach ( Capture option in match . Groups [ "option" ] . Captures )
733729 {
734730 var parts = option . Value . Split ( '=' ) ;
735- _allOptions . Add ( parts [ 0 ] , parts [ 1 ] ) ;
736- ParseOption ( parts [ 0 ] . Trim ( ) , Uri . UnescapeDataString ( parts [ 1 ] . Trim ( ) ) ) ;
731+ var name = parts [ 0 ] . Trim ( ) ;
732+ var value = Uri . UnescapeDataString ( parts [ 1 ] . Trim ( ) ) ;
733+ _allOptions . Add ( name , value ) ;
734+ ParseOption ( name , value ) ;
737735 }
738736 }
739737
@@ -1254,23 +1252,20 @@ private List<string> GetHostsFromSrvRecords(IEnumerable<SrvRecord> srvRecords)
12541252 return hosts ;
12551253 }
12561254
1257- private List < string > GetOptionsFromTxtRecords ( List < TxtRecord > txtRecords )
1255+ private NameValueCollection GetResolvedOptionsFromTxtRecords ( IReadOnlyCollection < TxtRecord > txtRecords )
12581256 {
12591257 if ( txtRecords . Count > 1 )
12601258 {
12611259 throw new MongoConfigurationException ( "Only 1 TXT record is allowed when using the SRV protocol." ) ;
12621260 }
12631261
1264- return txtRecords . Select ( tr => tr . Strings . Aggregate ( "" , ( acc , s ) => acc + Uri . UnescapeDataString ( s ) ) ) . ToList ( ) ;
1265- }
1262+ var txtRecord = txtRecords . FirstOrDefault ( ) ;
12661263
1267- private NameValueCollection GetResolvedOptions ( List < string > options )
1268- {
12691264 // Build a dummy connection string in order to parse the options
12701265 var dummyConnectionString = "mongodb://localhost/" ;
1271- if ( options . Count > 0 )
1266+ if ( txtRecord != null )
12721267 {
1273- dummyConnectionString += "?" + string . Join ( "& " , options ) ;
1268+ dummyConnectionString += "?" + string . Join ( "" , txtRecord . Strings ) ;
12741269 }
12751270 var dnsConnectionString = new ConnectionString ( dummyConnectionString ) ;
12761271 ValidateResolvedOptions ( dnsConnectionString . AllOptionNames ) ;
0 commit comments