Skip to content

Commit

Permalink
Merge pull request #1647 from skalenetwork/beta
Browse files Browse the repository at this point in the history
2.0.2
  • Loading branch information
DmytroNazarenko authored Nov 30, 2023
2 parents f57d757 + c812d17 commit 1b71bb8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
2.0.2
56 changes: 35 additions & 21 deletions npms/skale-owasp/owaspUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export function toFloat( value ) {
}

export function validateURL( s ) {
const u = toURL( s );
if( u == null )
const url = toURL( s );
if( url == null )
return false;
return true;
}
Expand All @@ -155,20 +155,20 @@ export function toURL( s ) {
const cnt = s.length;
if( s[cnt - 1] == sc ) {
const ss = s.substring( 1, cnt - 1 );
const u = toURL( ss );
if( u != null && u != undefined )
u.strStrippedStringComma = sc;
return u;
const url = toURL( ss );
if( url != null && url != undefined )
url.strStrippedStringComma = sc;
return url;
}
return null;
}
const u = new URL( s );
if( !u.hostname )
const url = new URL( s );
if( !url.hostname )
return null;
if( u.hostname.length === 0 )
if( url.hostname.length === 0 )
return null;
u.strStrippedStringComma = null;
return u;
url.strStrippedStringComma = null;
return url;
} catch ( err ) {
return null;
}
Expand All @@ -177,10 +177,10 @@ export function toURL( s ) {
export function toStringURL( s, defValue ) {
defValue = defValue || "";
try {
const u = toURL( s );
if( u == null || u == undefined )
const url = toURL( s );
if( url == null || url == undefined )
return defValue;
return u.toString();
return url.toString();
} catch ( err ) {
return defValue;
}
Expand All @@ -190,8 +190,8 @@ export function isUrlHTTP( strURL ) {
try {
if( !validateURL( strURL ) )
return false;
const u = new URL( strURL );
if( u.protocol == "http:" || u.protocol == "https:" )
const url = new URL( strURL );
if( url.protocol == "http:" || url.protocol == "https:" )
return true;
} catch ( err ) {
}
Expand All @@ -202,8 +202,8 @@ export function isUrlWS( strURL ) {
try {
if( !validateURL( strURL ) )
return false;
const u = new URL( strURL );
if( u.protocol == "ws:" || u.protocol == "wss:" )
const url = new URL( strURL );
if( url.protocol == "ws:" || url.protocol == "wss:" )
return true;
} catch ( err ) {
}
Expand Down Expand Up @@ -291,16 +291,16 @@ export function verifyArgumentWithNonEmptyValue( joArg ) {
export function verifyArgumentIsURL( joArg ) {
try {
verifyArgumentWithNonEmptyValue( joArg );
const u = toURL( joArg.value );
if( u == null ) {
const url = toURL( joArg.value );
if( url == null ) {
console.log(
cc.fatal( "(OWASP) CRITICAL ERROR:" ) + cc.error( " value " ) +
cc.warning( joArg.value ) + cc.error( " of argument " ) + cc.info( joArg.name ) +
cc.error( " must be valid URL" )
);
process.exit( 126 );
}
if( u.hostname.length <= 0 ) {
if( url.hostname.length <= 0 ) {
console.log( cc.fatal(
"(OWASP) CRITICAL ERROR:" ) + cc.error( " value " ) + cc.warning( joArg.value ) +
cc.error( " of argument " ) + cc.info( joArg.name ) +
Expand Down Expand Up @@ -729,10 +729,24 @@ export function fnAddressImpl_() {
}

export function getEthersProviderFromURL( strURL ) {
const url = new URL( strURL );
let userName = null, userPwd = null;
if( url.username ) {
userName = url.username;
userPwd = url.password;
url.username = "";
url.password = "";
strURL = url.href; // remove credentials
}
const joConnectionInfo = { // see https://docs.ethers.io/v5/api/utils/web/#ConnectionInfo
url: strURL,
allowInsecureAuthentication: true
};
if( userName ) {
joConnectionInfo.user = userName;
if( userPwd )
joConnectionInfo.password = userPwd;
}
const ethersProvider = new ethersMod.ethers.providers.JsonRpcProvider( joConnectionInfo );
return ethersProvider;
}
Expand Down

0 comments on commit 1b71bb8

Please sign in to comment.