Skip to content

Commit

Permalink
fix(core)- fixed malformed URL links
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelly011s committed Feb 1, 2023
1 parent abfec11 commit e9e91e8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/client/helpers/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ export function dateObjectToISOString(value: DateObject) {
* @returns {JSX} returns a JSX Element
*/
export function stringToHTMLWithLinks(string: string) {
const addHttpRegex = /(^|\b)www\./ig;
//const addHttpRegex = /(^|\b)www\./ig;
// eslint-disable-next-line max-len, no-useless-escape
const urlRegex = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%~*@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/g;
let content = string.replace(addHttpRegex, '$1https://www.');
content = content.replace(
//let content = string.replace(addHttpRegex, '$1https://www.');
let content = string.replace(
urlRegex,
'<a href="$1" target="_blank">$1</a>'
);
const sanitizedHtml = DOMPurify.sanitize(content);
const sanitizedHtml = DOMPurify.sanitize(content, { ADD_ATTR: ['target'] });
// eslint-disable-next-line react/no-danger
return <span dangerouslySetInnerHTML={{__html: sanitizedHtml}}/>;
}
Expand Down

0 comments on commit e9e91e8

Please sign in to comment.