fix: Render valid urls only in custom attributes (#3921)
This commit is contained in:
@@ -37,3 +37,9 @@ export const accountIdFromPathname = pathname => {
|
||||
const accountId = isScoped ? Number(urlParam) : '';
|
||||
return accountId;
|
||||
};
|
||||
|
||||
export const isValidURL = value => {
|
||||
/* eslint-disable no-useless-escape */
|
||||
const URL_REGEX = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/gm;
|
||||
return URL_REGEX.test(value);
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
frontendURL,
|
||||
conversationUrl,
|
||||
accountIdFromPathname,
|
||||
isValidURL,
|
||||
} from '../URLHelper';
|
||||
|
||||
describe('#URL Helpers', () => {
|
||||
@@ -48,4 +49,13 @@ describe('#URL Helpers', () => {
|
||||
expect(accountIdFromPathname('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValidURL', () => {
|
||||
it('should return true if valid url is passed', () => {
|
||||
expect(isValidURL('https://chatwoot.com')).toBe(true);
|
||||
});
|
||||
it('should return false if invalid url is passed', () => {
|
||||
expect(isValidURL('alert.window')).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user