-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sequenceProvider): feedergatewayUrl and gatewayUrl
- Loading branch information
1 parent
7e1d5b2
commit e236d23
Showing
4 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* RegExps. | ||
* A URL must match #1 and then at least one of #2/#3. | ||
* Use two levels of REs to avoid REDOS. | ||
*/ | ||
|
||
/** | ||
* Inspired from https://github.com/segmentio/is-url | ||
*/ | ||
|
||
const protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/; | ||
|
||
const localhostDomainRE = /^localhost[:?\d]*(?:[^:?\d]\S*)?$/; | ||
const nonLocalhostDomainRE = /^[^\s.]+\.\S{2,}$/; | ||
|
||
/** | ||
* Loosely validate a URL `string`. | ||
* @param {String} s | ||
* @return {Boolean} | ||
*/ | ||
export function isUrl(s: string): boolean { | ||
if (typeof s !== 'string') { | ||
return false; | ||
} | ||
|
||
const match = s.match(protocolAndDomainRE); | ||
if (!match) { | ||
return false; | ||
} | ||
|
||
const everythingAfterProtocol = match[1]; | ||
if (!everythingAfterProtocol) { | ||
return false; | ||
} | ||
|
||
if ( | ||
localhostDomainRE.test(everythingAfterProtocol) || | ||
nonLocalhostDomainRE.test(everythingAfterProtocol) | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} |