@@ -352,13 +352,14 @@ private void SetDefaultOptions()
352
352
_options = new Dictionary < string , object > ( DefaultValues ) ;
353
353
}
354
354
355
+ // it is expected the hostname do be at least 2 characters to prevent possible ambiguity (DNET-892)
355
356
private void ParseConnectionInfo ( string connectionInfo )
356
357
{
357
358
connectionInfo = connectionInfo . Trim ( ) ;
358
359
359
360
{
360
- // URL style inet://host :port/database
361
- var match = Regex . Match ( connectionInfo , "^inet://(?<host>[A-Za-z0-9\\ .]+) :(?<port>\\ d+)/(?<database>.+)$" ) ;
361
+ // URL style inet://[hostv6] :port/database
362
+ var match = Regex . Match ( connectionInfo , "^inet://\\ [ (?<host>[A-Za-z0-9:]{2,}) \\ ] :(?<port>\\ d+)/(?<database>.+)$" ) ;
362
363
if ( match . Success )
363
364
{
364
365
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -368,8 +369,8 @@ private void ParseConnectionInfo(string connectionInfo)
368
369
}
369
370
}
370
371
{
371
- // URL style inet://[hostv6] :port/database
372
- var match = Regex . Match ( connectionInfo , "^inet://\\ [ (?<host>[A-Za-z0-9:]+) \\ ] :(?<port>\\ d+)/(?<database>.+)$" ) ;
372
+ // URL style inet://host :port/database
373
+ var match = Regex . Match ( connectionInfo , "^inet://(?<host>[A-Za-z0-9\\ .-]{2,}) :(?<port>\\ d+)/(?<database>.+)$" ) ;
373
374
if ( match . Success )
374
375
{
375
376
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -380,7 +381,7 @@ private void ParseConnectionInfo(string connectionInfo)
380
381
}
381
382
{
382
383
// URL style inet://host/database
383
- var match = Regex . Match ( connectionInfo , "^inet://(?<host>[A-Za-z0-9\\ .:]+ )/(?<database>.+)$" ) ;
384
+ var match = Regex . Match ( connectionInfo , "^inet://(?<host>[A-Za-z0-9\\ .:-]{2,} )/(?<database>.+)$" ) ;
384
385
if ( match . Success )
385
386
{
386
387
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -399,8 +400,8 @@ private void ParseConnectionInfo(string connectionInfo)
399
400
}
400
401
}
401
402
{
402
- // new style //host :port/database
403
- var match = Regex . Match ( connectionInfo , "^//(?<host>[A-Za-z0-9\\ .]+) :(?<port>\\ d+)/(?<database>.+)$" ) ;
403
+ // new style //[hostv6] :port/database
404
+ var match = Regex . Match ( connectionInfo , "^//\\ [ (?<host>[A-Za-z0-9:]{2,}) \\ ] :(?<port>\\ d+)/(?<database>.+)$" ) ;
404
405
if ( match . Success )
405
406
{
406
407
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -410,8 +411,8 @@ private void ParseConnectionInfo(string connectionInfo)
410
411
}
411
412
}
412
413
{
413
- // new style //[hostv6] :port/database
414
- var match = Regex . Match ( connectionInfo , "^//\\ [ (?<host>[A-Za-z0-9:]+) \\ ] :(?<port>\\ d+)/(?<database>.+)$" ) ;
414
+ // new style //host :port/database
415
+ var match = Regex . Match ( connectionInfo , "^//(?<host>[A-Za-z0-9\\ .-]{2,}) :(?<port>\\ d+)/(?<database>.+)$" ) ;
415
416
if ( match . Success )
416
417
{
417
418
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -422,7 +423,7 @@ private void ParseConnectionInfo(string connectionInfo)
422
423
}
423
424
{
424
425
// new style //host/database
425
- var match = Regex . Match ( connectionInfo , "^//(?<host>[A-Za-z0-9\\ .:]+ )/(?<database>.+)$" ) ;
426
+ var match = Regex . Match ( connectionInfo , "^//(?<host>[A-Za-z0-9\\ .:-]{2,} )/(?<database>.+)$" ) ;
426
427
if ( match . Success )
427
428
{
428
429
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -432,7 +433,7 @@ private void ParseConnectionInfo(string connectionInfo)
432
433
}
433
434
{
434
435
// old style host:X:\database
435
- var match = Regex . Match ( connectionInfo , "^(?<host>[A-Za-z0-9\\ .:]+ ):(?<database>[A-Za-z]:\\ \\ .+)$" ) ;
436
+ var match = Regex . Match ( connectionInfo , "^(?<host>[A-Za-z0-9\\ .:-]{2,} ):(?<database>[A-Za-z]:\\ \\ .+)$" ) ;
436
437
if ( match . Success )
437
438
{
438
439
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -442,7 +443,7 @@ private void ParseConnectionInfo(string connectionInfo)
442
443
}
443
444
{
444
445
// old style host/port:database
445
- var match = Regex . Match ( connectionInfo , "^(?<host>[A-Za-z0-9\\ .:]+ )/(?<port>\\ d+):(?<database>.+)$" ) ;
446
+ var match = Regex . Match ( connectionInfo , "^(?<host>[A-Za-z0-9\\ .:-]{2,} )/(?<port>\\ d+):(?<database>.+)$" ) ;
446
447
if ( match . Success )
447
448
{
448
449
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -453,7 +454,7 @@ private void ParseConnectionInfo(string connectionInfo)
453
454
}
454
455
{
455
456
// old style host:database
456
- var match = Regex . Match ( connectionInfo , "^(?<host>[A-Za-z0-9\\ .:]+ ):(?<database>.+)$" ) ;
457
+ var match = Regex . Match ( connectionInfo , "^(?<host>[A-Za-z0-9\\ .:-]{2,} ):(?<database>.+)$" ) ;
457
458
if ( match . Success )
458
459
{
459
460
_options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
0 commit comments