@@ -39,24 +39,29 @@ Item {
3939 function isUrl (text ) {
4040 if (! text || text .includes (" " )) return false ;
4141
42- if (/ ^ https? :\/\/ / i .test (text)) return true ;
42+ const protocolPattern = / ^ [a-z0-9 ] + :\/\/ \S + / i ;
43+ if (protocolPattern .test (text)) return true ;
4344
44- const localhostPattern = / ^ localhost(: [ 0-9 ] + ) ? ( \/ \S * )? $ / i ;
45+ const localhostPattern = / ^ localhost(\/ \S * )? $ / i ;
4546 const ipPattern = / ^ (?:(?:25[0-5 ] | 2[0-4 ][0-9 ] | [01] ? [0-9 ][0-9 ] ? )\. ){3} (?:25[0-5 ] | 2[0-4 ][0-9 ] | [01] ? [0-9 ][0-9 ] ? )(:[0-9 ] + )? (\/ \S * )? $ / ;
46- const domainPattern = / ^ [a-zA-Z0-9 ] ([a-zA-Z0-9 -] {0,61} [a-zA-Z0-9 ] )? (\. [a-zA-Z ] {2,} )+ (:[0-9 ] + )? (\/ \S * )? $ / ;
47+ const domainPattern = / ^ ([a-zA-Z0-9 -] {1,63} \. )+ [a-zA-Z ] {2,} (:[0-9 ] + )? (\/ \S * )? $ / i ;
48+ const hostPortPattern = / ^ [a-zA-Z0-9 -] + :[0-9 ] + (\/ \S * )? $ / i ;
4749
48- return localhostPattern .test (text) || ipPattern .test (text) || domainPattern .test (text);
50+ return localhostPattern .test (text) || ipPattern .test (text) || domainPattern .test (text) || hostPortPattern . test (text) ;
4951 }
5052
5153 function normalizeUrl (text ) {
5254 text = text .trim ();
5355 if (! text) return " " ;
54- if (/ ^ [a-z0-9 ] + :\/\/ / i .test (text)) return text;
5556
56- const isLocal = / ^ localhost(:[0-9 ] + )? (\/ \S * )? $ / i .test (text) ||
57- / ^ (?:(?:25[0-5 ] | 2[0-4 ][0-9 ] | [01] ? [0-9 ][0-9 ] ? )\. ){3} (?:25[0-5 ] | 2[0-4 ][0-9 ] | [01] ? [0-9 ][0-9 ] ? )(:[0-9 ] + )? (\/ \S * )? $ / .test (text);
57+ const protocolPattern = / ^ [a-z0-9 ] + :\/\/ \S + / i ;
58+ if (protocolPattern .test (text)) return text;
59+
60+ const localhostPattern = / ^ localhost(\/ \S * )? $ / i ;
61+ const ipPattern = / ^ (?:(?:25[0-5 ] | 2[0-4 ][0-9 ] | [01] ? [0-9 ][0-9 ] ? )\. ){3} (?:25[0-5 ] | 2[0-4 ][0-9 ] | [01] ? [0-9 ][0-9 ] ? )(:[0-9 ] + )? (\/ \S * )? $ / ;
62+ const hostPortPattern = / ^ [a-zA-Z0-9 -] + :[0-9 ] + (\/ \S * )? $ / i ;
5863
59- if (isLocal ) {
64+ if (localhostPattern . test (text) || ipPattern . test (text) || hostPortPattern . test (text) ) {
6065 return " http://" + text;
6166 }
6267
0 commit comments