fix: Improve performance of base64 detection regex

This commit is contained in:
Tom Moor
2023-10-21 21:29:06 -04:00
parent 0518cdc6d9
commit 9f6c90c86a
3 changed files with 43 additions and 5 deletions

View File

@@ -86,6 +86,17 @@ export function isExternalUrl(url: string) {
return !!url && !isInternalUrl(url) && !url.startsWith(creatingUrlPrefix);
}
/**
* Returns match if the given string is a base64 encoded url.
*
* @param url The url to check.
* @returns A RegExp match if the url is base64, false otherwise.
*/
export function isBase64Url(url: string) {
const match = url.match(/^(data:[a-z]+\/[^;]+;base64,(.*))/i);
return match ? match : false;
}
/**
* For use in the editor, this function will ensure that a url is
* potentially valid, and filter out unsupported and malicious protocols.