@@ -621,10 +621,12 @@ function URI_VLESS() {
621621 } ;
622622 const params = { } ;
623623 for ( const addon of addons . split ( '&' ) ) {
624- const [ key , valueRaw ] = addon . split ( '=' ) ;
625- let value = valueRaw ;
626- value = decodeURIComponent ( valueRaw ) ;
627- params [ key ] = value ;
624+ if ( addon ) {
625+ const [ key , valueRaw ] = addon . split ( '=' ) ;
626+ let value = valueRaw ;
627+ value = decodeURIComponent ( valueRaw ) ;
628+ params [ key ] = value ;
629+ }
628630 }
629631
630632 proxy . name =
@@ -781,17 +783,19 @@ function URI_AnyTLS() {
781783 } ;
782784
783785 for ( const addon of addons . split ( '&' ) ) {
784- let [ key , value ] = addon . split ( '=' ) ;
785- key = key . replace ( / _ / g, '-' ) ;
786- value = decodeURIComponent ( value ) ;
787- if ( [ 'alpn' ] . includes ( key ) ) {
788- proxy [ key ] = value ? value . split ( ',' ) : undefined ;
789- } else if ( [ 'insecure' ] . includes ( key ) ) {
790- proxy [ 'skip-cert-verify' ] = / ( T R U E ) | 1 / i. test ( value ) ;
791- } else if ( [ 'udp' ] . includes ( key ) ) {
792- proxy [ key ] = / ( T R U E ) | 1 / i. test ( value ) ;
793- } else if ( ! Object . keys ( proxy ) . includes ( key ) ) {
794- proxy [ key ] = value ;
786+ if ( addon ) {
787+ let [ key , value ] = addon . split ( '=' ) ;
788+ key = key . replace ( / _ / g, '-' ) ;
789+ value = decodeURIComponent ( value ) ;
790+ if ( [ 'alpn' ] . includes ( key ) ) {
791+ proxy [ key ] = value ? value . split ( ',' ) : undefined ;
792+ } else if ( [ 'insecure' ] . includes ( key ) ) {
793+ proxy [ 'skip-cert-verify' ] = / ( T R U E ) | 1 / i. test ( value ) ;
794+ } else if ( [ 'udp' ] . includes ( key ) ) {
795+ proxy [ key ] = / ( T R U E ) | 1 / i. test ( value ) ;
796+ } else if ( ! Object . keys ( proxy ) . includes ( key ) ) {
797+ proxy [ key ] = value ;
798+ }
795799 }
796800 }
797801 if ( [ 'tcp' ] . includes ( proxy . network ) && ! proxy [ 'reality-opts' ] ) {
@@ -863,10 +867,12 @@ function URI_Hysteria2() {
863867
864868 const params = { } ;
865869 for ( const addon of addons . split ( '&' ) ) {
866- const [ key , valueRaw ] = addon . split ( '=' ) ;
867- let value = valueRaw ;
868- value = decodeURIComponent ( valueRaw ) ;
869- params [ key ] = value ;
870+ if ( addon ) {
871+ const [ key , valueRaw ] = addon . split ( '=' ) ;
872+ let value = valueRaw ;
873+ value = decodeURIComponent ( valueRaw ) ;
874+ params [ key ] = value ;
875+ }
870876 }
871877
872878 proxy . sni = params . sni ;
@@ -925,30 +931,32 @@ function URI_Hysteria() {
925931 } ;
926932 const params = { } ;
927933 for ( const addon of addons . split ( '&' ) ) {
928- let [ key , value ] = addon . split ( '=' ) ;
929- key = key . replace ( / _ / , '-' ) ;
930- value = decodeURIComponent ( value ) ;
931- if ( [ 'alpn' ] . includes ( key ) ) {
932- proxy [ key ] = value ? value . split ( ',' ) : undefined ;
933- } else if ( [ 'insecure' ] . includes ( key ) ) {
934- proxy [ 'skip-cert-verify' ] = / ( T R U E ) | 1 / i. test ( value ) ;
935- } else if ( [ 'auth' ] . includes ( key ) ) {
936- proxy [ 'auth-str' ] = value ;
937- } else if ( [ 'mport' ] . includes ( key ) ) {
938- proxy [ 'ports' ] = value ;
939- } else if ( [ 'obfsParam' ] . includes ( key ) ) {
940- proxy [ 'obfs' ] = value ;
941- } else if ( [ 'upmbps' ] . includes ( key ) ) {
942- proxy [ 'up' ] = value ;
943- } else if ( [ 'downmbps' ] . includes ( key ) ) {
944- proxy [ 'down' ] = value ;
945- } else if ( [ 'obfs' ] . includes ( key ) ) {
946- // obfs: Obfuscation mode (optional, empty or "xplus")
947- proxy [ '_obfs' ] = value || '' ;
948- } else if ( [ 'fast-open' , 'peer' ] . includes ( key ) ) {
949- params [ key ] = value ;
950- } else if ( ! Object . keys ( proxy ) . includes ( key ) ) {
951- proxy [ key ] = value ;
934+ if ( addon ) {
935+ let [ key , value ] = addon . split ( '=' ) ;
936+ key = key . replace ( / _ / , '-' ) ;
937+ value = decodeURIComponent ( value ) ;
938+ if ( [ 'alpn' ] . includes ( key ) ) {
939+ proxy [ key ] = value ? value . split ( ',' ) : undefined ;
940+ } else if ( [ 'insecure' ] . includes ( key ) ) {
941+ proxy [ 'skip-cert-verify' ] = / ( T R U E ) | 1 / i. test ( value ) ;
942+ } else if ( [ 'auth' ] . includes ( key ) ) {
943+ proxy [ 'auth-str' ] = value ;
944+ } else if ( [ 'mport' ] . includes ( key ) ) {
945+ proxy [ 'ports' ] = value ;
946+ } else if ( [ 'obfsParam' ] . includes ( key ) ) {
947+ proxy [ 'obfs' ] = value ;
948+ } else if ( [ 'upmbps' ] . includes ( key ) ) {
949+ proxy [ 'up' ] = value ;
950+ } else if ( [ 'downmbps' ] . includes ( key ) ) {
951+ proxy [ 'down' ] = value ;
952+ } else if ( [ 'obfs' ] . includes ( key ) ) {
953+ // obfs: Obfuscation mode (optional, empty or "xplus")
954+ proxy [ '_obfs' ] = value || '' ;
955+ } else if ( [ 'fast-open' , 'peer' ] . includes ( key ) ) {
956+ params [ key ] = value ;
957+ } else if ( ! Object . keys ( proxy ) . includes ( key ) ) {
958+ proxy [ key ] = value ;
959+ }
952960 }
953961 }
954962
@@ -1000,22 +1008,24 @@ function URI_TUIC() {
10001008 } ;
10011009
10021010 for ( const addon of addons . split ( '&' ) ) {
1003- let [ key , value ] = addon . split ( '=' ) ;
1004- key = key . replace ( / _ / g, '-' ) ;
1005- value = decodeURIComponent ( value ) ;
1006- if ( [ 'alpn' ] . includes ( key ) ) {
1007- proxy [ key ] = value ? value . split ( ',' ) : undefined ;
1008- } else if ( [ 'allow-insecure' , 'insecure' ] . includes ( key ) ) {
1009- proxy [ 'skip-cert-verify' ] = / ( T R U E ) | 1 / i. test ( value ) ;
1010- } else if ( [ 'fast-open' ] . includes ( key ) ) {
1011- proxy . tfo = true ;
1012- } else if ( [ 'disable-sni' , 'reduce-rtt' ] . includes ( key ) ) {
1013- proxy [ key ] = / ( T R U E ) | 1 / i. test ( value ) ;
1014- } else if ( key === 'congestion-control' ) {
1015- proxy [ 'congestion-controller' ] = value ;
1016- delete proxy [ key ] ;
1017- } else if ( ! Object . keys ( proxy ) . includes ( key ) ) {
1018- proxy [ key ] = value ;
1011+ if ( addon ) {
1012+ let [ key , value ] = addon . split ( '=' ) ;
1013+ key = key . replace ( / _ / g, '-' ) ;
1014+ value = decodeURIComponent ( value ) ;
1015+ if ( [ 'alpn' ] . includes ( key ) ) {
1016+ proxy [ key ] = value ? value . split ( ',' ) : undefined ;
1017+ } else if ( [ 'allow-insecure' , 'insecure' ] . includes ( key ) ) {
1018+ proxy [ 'skip-cert-verify' ] = / ( T R U E ) | 1 / i. test ( value ) ;
1019+ } else if ( [ 'fast-open' ] . includes ( key ) ) {
1020+ proxy . tfo = true ;
1021+ } else if ( [ 'disable-sni' , 'reduce-rtt' ] . includes ( key ) ) {
1022+ proxy [ key ] = / ( T R U E ) | 1 / i. test ( value ) ;
1023+ } else if ( key === 'congestion-control' ) {
1024+ proxy [ 'congestion-controller' ] = value ;
1025+ delete proxy [ key ] ;
1026+ } else if ( ! Object . keys ( proxy ) . includes ( key ) ) {
1027+ proxy [ key ] = value ;
1028+ }
10191029 }
10201030 }
10211031
@@ -1062,43 +1072,45 @@ function URI_WireGuard() {
10621072 udp : true ,
10631073 } ;
10641074 for ( const addon of addons . split ( '&' ) ) {
1065- let [ key , value ] = addon . split ( '=' ) ;
1066- key = key . replace ( / _ / , '-' ) ;
1067- value = decodeURIComponent ( value ) ;
1068- if ( [ 'reserved' ] . includes ( key ) ) {
1069- const parsed = value
1070- . split ( ',' )
1071- . map ( ( i ) => parseInt ( i . trim ( ) , 10 ) )
1072- . filter ( ( i ) => Number . isInteger ( i ) ) ;
1073- if ( parsed . length === 3 ) {
1074- proxy [ key ] = parsed ;
1075- }
1076- } else if ( [ 'address' , 'ip' ] . includes ( key ) ) {
1077- value . split ( ',' ) . map ( ( i ) => {
1078- const ip = i
1079- . trim ( )
1080- . replace ( / \/ \d + $ / , '' )
1081- . replace ( / ^ \[ / , '' )
1082- . replace ( / \] $ / , '' ) ;
1083- if ( isIPv4 ( ip ) ) {
1084- proxy . ip = ip ;
1085- } else if ( isIPv6 ( ip ) ) {
1086- proxy . ipv6 = ip ;
1075+ if ( addon ) {
1076+ let [ key , value ] = addon . split ( '=' ) ;
1077+ key = key . replace ( / _ / , '-' ) ;
1078+ value = decodeURIComponent ( value ) ;
1079+ if ( [ 'reserved' ] . includes ( key ) ) {
1080+ const parsed = value
1081+ . split ( ',' )
1082+ . map ( ( i ) => parseInt ( i . trim ( ) , 10 ) )
1083+ . filter ( ( i ) => Number . isInteger ( i ) ) ;
1084+ if ( parsed . length === 3 ) {
1085+ proxy [ key ] = parsed ;
1086+ }
1087+ } else if ( [ 'address' , 'ip' ] . includes ( key ) ) {
1088+ value . split ( ',' ) . map ( ( i ) => {
1089+ const ip = i
1090+ . trim ( )
1091+ . replace ( / \/ \d + $ / , '' )
1092+ . replace ( / ^ \[ / , '' )
1093+ . replace ( / \] $ / , '' ) ;
1094+ if ( isIPv4 ( ip ) ) {
1095+ proxy . ip = ip ;
1096+ } else if ( isIPv6 ( ip ) ) {
1097+ proxy . ipv6 = ip ;
1098+ }
1099+ } ) ;
1100+ } else if ( [ 'mtu' ] . includes ( key ) ) {
1101+ const parsed = parseInt ( value . trim ( ) , 10 ) ;
1102+ if ( Number . isInteger ( parsed ) ) {
1103+ proxy [ key ] = parsed ;
10871104 }
1088- } ) ;
1089- } else if ( [ 'mtu' ] . includes ( key ) ) {
1090- const parsed = parseInt ( value . trim ( ) , 10 ) ;
1091- if ( Number . isInteger ( parsed ) ) {
1092- proxy [ key ] = parsed ;
1105+ } else if ( / p u b l i c k e y / i. test ( key ) ) {
1106+ proxy [ 'public-key' ] = value ;
1107+ } else if ( / p r i v a t e k e y / i. test ( key ) ) {
1108+ proxy [ 'private-key' ] = value ;
1109+ } else if ( [ 'udp' ] . includes ( key ) ) {
1110+ proxy [ key ] = / ( T R U E ) | 1 / i. test ( value ) ;
1111+ } else if ( ! [ ...Object . keys ( proxy ) , 'flag' ] . includes ( key ) ) {
1112+ proxy [ key ] = value ;
10931113 }
1094- } else if ( / p u b l i c k e y / i. test ( key ) ) {
1095- proxy [ 'public-key' ] = value ;
1096- } else if ( / p r i v a t e k e y / i. test ( key ) ) {
1097- proxy [ 'private-key' ] = value ;
1098- } else if ( [ 'udp' ] . includes ( key ) ) {
1099- proxy [ key ] = / ( T R U E ) | 1 / i. test ( value ) ;
1100- } else if ( ! [ ...Object . keys ( proxy ) , 'flag' ] . includes ( key ) ) {
1101- proxy [ key ] = value ;
11021114 }
11031115 }
11041116
0 commit comments