File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
packages/faucet-client/src Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 11import fetch from "cross-fetch" ;
22
3+ /**
4+ * Strip trailing `/`s
5+ */
6+ function stripTrailingSlash ( baseUrl : string ) : string {
7+ // Limit the amount of / stripped to avoid potential regex DoS
8+ return baseUrl . replace ( / ( \/ { 0 , 20 } ) $ / , "" ) ;
9+ }
10+
311export class FaucetClient {
412 private readonly baseUrl : string ;
513
614 public constructor ( baseUrl : string ) {
715 if ( ! baseUrl . match ( / ^ h t t p s ? : \/ \/ / ) ) {
816 throw new Error ( "Expected base url to start with http:// or https://" ) ;
917 }
10-
11- // Strip trailing /
12- const strippedBaseUrl = baseUrl . replace ( / ( \/ + ) $ / , "" ) ;
13- this . baseUrl = strippedBaseUrl ;
18+ this . baseUrl = stripTrailingSlash ( baseUrl ) ;
1419 }
1520
1621 public async credit ( address : string , denom : string ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments