@@ -352,13 +352,14 @@ private void SetDefaultOptions()
352352 _options = new Dictionary < string , object > ( DefaultValues ) ;
353353 }
354354
355+ // it is expected the hostname do be at least 2 characters to prevent possible ambiguity (DNET-892)
355356 private void ParseConnectionInfo ( string connectionInfo )
356357 {
357358 connectionInfo = connectionInfo . Trim ( ) ;
358359
359360 {
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>.+)$" ) ;
362363 if ( match . Success )
363364 {
364365 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -368,8 +369,8 @@ private void ParseConnectionInfo(string connectionInfo)
368369 }
369370 }
370371 {
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>.+)$" ) ;
373374 if ( match . Success )
374375 {
375376 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -380,7 +381,7 @@ private void ParseConnectionInfo(string connectionInfo)
380381 }
381382 {
382383 // 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>.+)$" ) ;
384385 if ( match . Success )
385386 {
386387 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -399,8 +400,8 @@ private void ParseConnectionInfo(string connectionInfo)
399400 }
400401 }
401402 {
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>.+)$" ) ;
404405 if ( match . Success )
405406 {
406407 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -410,8 +411,8 @@ private void ParseConnectionInfo(string connectionInfo)
410411 }
411412 }
412413 {
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>.+)$" ) ;
415416 if ( match . Success )
416417 {
417418 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -422,7 +423,7 @@ private void ParseConnectionInfo(string connectionInfo)
422423 }
423424 {
424425 // 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>.+)$" ) ;
426427 if ( match . Success )
427428 {
428429 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -432,7 +433,7 @@ private void ParseConnectionInfo(string connectionInfo)
432433 }
433434 {
434435 // 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]:\\ \\ .+)$" ) ;
436437 if ( match . Success )
437438 {
438439 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -442,7 +443,7 @@ private void ParseConnectionInfo(string connectionInfo)
442443 }
443444 {
444445 // 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>.+)$" ) ;
446447 if ( match . Success )
447448 {
448449 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
@@ -453,7 +454,7 @@ private void ParseConnectionInfo(string connectionInfo)
453454 }
454455 {
455456 // 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>.+)$" ) ;
457458 if ( match . Success )
458459 {
459460 _options [ DefaultKeyCatalog ] = match . Groups [ "database" ] . Value ;
0 commit comments