File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { isWindows } from '../../util/ui';
88import  {  WarningIcon ,  Icon  }  from  '../../icons' ; 
99
1010import  {  isValidPortConfiguration ,  ProxyStore  }  from  '../../model/proxy-store' ; 
11- import  {  isValidHostname  }  from  '../../model/network' ; 
11+ import  {  isValidHostnamePattern  }  from  '../../model/network' ; 
1212import  { 
1313    serverVersion , 
1414    desktopVersion , 
@@ -112,7 +112,7 @@ const InputClearButton = styled(IconButton)`
112112    right: 2px; 
113113` ; 
114114
115- const  hostnameValidation  =  inputValidation ( isValidHostname ,  "Should be a valid hostname" ) ; 
115+ const  hostnameValidation  =  inputValidation ( isValidHostnamePattern ,  "Should be a valid hostname (with optional * wildcards) " ) ; 
116116
117117const  isAbsoluteWindowsPath  =  ( path : string )  =>  / ^ ( [ a - z A - Z ] : [ \\ \/ ] | [ \\ \/ ] ) ( (?: [ ^ < > : " \/ \\ | ? * ] + ) [ \\ \/ ] ? ) * $ / . test ( path ) ; 
118118const  isAbsolutePosixPath  =  ( path : string )  =>  / ^ \/ (?: [ ^ / ] + \/ ? ) * $ / . test ( path ) ; 
Original file line number Diff line number Diff line change @@ -9,6 +9,21 @@ export function isValidHost(host: string | undefined): boolean {
99    return  ! ! host ?. match ( / ^ [ A - Z a - z 0 - 9 \- . ] + ( : \d + ) ? $ / ) ; 
1010} 
1111
12+ export  function  isValidHostnamePattern ( pattern : string  |  undefined ) : boolean  { 
13+     if  ( ! pattern )  return  false ; 
14+ 
15+     if  ( isValidHostname ( pattern ) )  return  true ; 
16+ 
17+     // Not a valid hostname. Is it a URLPatternb wildcard pattern then? 
18+     // Replace * with a letter to test if it's valid & usable: 
19+ 
20+     const  testHostname  =  pattern . replace ( / \* / g,  'Z' ) ; 
21+     return  isValidHostname ( testHostname )  && 
22+         ( ! ( 'URLPattern'  in  window )  ||  // On old Electron, just allow anything 
23+         // Use any here because TS doesn't have types yet: 
24+         new  ( window . URLPattern  as  any ) ( `https://${ pattern }  ` ) . test ( `https://${ testHostname }  ` ) ) ; 
25+ } 
26+ 
1227export  function  isValidHostname ( hostname : string  |  undefined ) : boolean  { 
1328    return  ! ! hostname ?. match ( / ^ [ A - Z a - z 0 - 9 \- . ] + $ / ) ; 
1429} 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments