@@ -556,9 +556,7 @@ public string GetOption(string name)
556
556
}
557
557
558
558
var txtRecords = _dnsResolver . ResolveTxtRecords ( host , cancellationToken ) ;
559
- var options = GetOptionsFromTxtRecords ( txtRecords ) ;
560
-
561
- var resolvedOptions = GetResolvedOptions ( options ) ;
559
+ var resolvedOptions = GetResolvedOptionsFromTxtRecords ( txtRecords ) ;
562
560
563
561
return BuildResolvedConnectionString ( resolvedScheme , hosts , resolvedOptions ) ;
564
562
}
@@ -606,9 +604,7 @@ public string GetOption(string name)
606
604
}
607
605
608
606
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 ) ;
612
608
613
609
return BuildResolvedConnectionString ( resolvedScheme , hosts , resolvedOptions ) ;
614
610
}
@@ -655,9 +651,9 @@ private ConnectionString BuildResolvedConnectionString(ConnectionStringScheme re
655
651
mergedOptions . AddRange (
656
652
resolvedOptions
657
653
. 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 ) } ") ) ) ;
661
657
662
658
if ( mergedOptions . Count > 0 )
663
659
{
@@ -732,8 +728,10 @@ private void ExtractOptions(Match match)
732
728
foreach ( Capture option in match . Groups [ "option" ] . Captures )
733
729
{
734
730
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 ) ;
737
735
}
738
736
}
739
737
@@ -1254,23 +1252,20 @@ private List<string> GetHostsFromSrvRecords(IEnumerable<SrvRecord> srvRecords)
1254
1252
return hosts ;
1255
1253
}
1256
1254
1257
- private List < string > GetOptionsFromTxtRecords ( List < TxtRecord > txtRecords )
1255
+ private NameValueCollection GetResolvedOptionsFromTxtRecords ( IReadOnlyCollection < TxtRecord > txtRecords )
1258
1256
{
1259
1257
if ( txtRecords . Count > 1 )
1260
1258
{
1261
1259
throw new MongoConfigurationException ( "Only 1 TXT record is allowed when using the SRV protocol." ) ;
1262
1260
}
1263
1261
1264
- return txtRecords . Select ( tr => tr . Strings . Aggregate ( "" , ( acc , s ) => acc + Uri . UnescapeDataString ( s ) ) ) . ToList ( ) ;
1265
- }
1262
+ var txtRecord = txtRecords . FirstOrDefault ( ) ;
1266
1263
1267
- private NameValueCollection GetResolvedOptions ( List < string > options )
1268
- {
1269
1264
// Build a dummy connection string in order to parse the options
1270
1265
var dummyConnectionString = "mongodb://localhost/" ;
1271
- if ( options . Count > 0 )
1266
+ if ( txtRecord != null )
1272
1267
{
1273
- dummyConnectionString += "?" + string . Join ( "& " , options ) ;
1268
+ dummyConnectionString += "?" + string . Join ( "" , txtRecord . Strings ) ;
1274
1269
}
1275
1270
var dnsConnectionString = new ConnectionString ( dummyConnectionString ) ;
1276
1271
ValidateResolvedOptions ( dnsConnectionString . AllOptionNames ) ;
0 commit comments