Skip to content

Commit

Permalink
fix: remove dangerouslySetInnerHTML from ContactLink
Browse files Browse the repository at this point in the history
  • Loading branch information
pnicolli committed Mar 19, 2024
1 parent 01b331e commit ff7bcab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 42 deletions.
67 changes: 25 additions & 42 deletions src/components/ItaliaTheme/View/Commons/ContactLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,61 +35,44 @@ const ContactLink = ({ tel, fax, email, label = true, strong = false }) => {
let ret_label = null;
let ret = null;

function ReplacePhoneNumbers(str, type) {
// eslint-disable-next-line no-useless-escape
let newhtml = str.replace(/\+?[0-9]( ?[0-9\/-]+)+.?[0-9]*/gm, function (v) {
let r =
"<a href='" +
type +
':' +
v.trim().replace(/-|\/|\s/gm, '') +
"' title='" +
(type === 'tel'
? intl.formatMessage(messages.call)
: intl.formatMessage(messages.call_fax)) +
"' >" +
v +
'</a>';
return r;
});
return newhtml;
}

function ReplaceEmails(str) {
let newhtml = str.replace(
/([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi,
function (v) {
let r =
"<a href='mailto:" +
v.trim().replace(/|\/|\s/gm, '') +
"' title='" +
intl.formatMessage(messages.write_to) +
"' >" +
v +
'</a>';
return r;
},
);
return newhtml;
}

if (tel) {
ret_label = intl.formatMessage(messages.telefono);
ret = ReplacePhoneNumbers(tel, 'tel');
ret = (
<a
href={`tel:${tel.trim().replace(/|\/|\s/gm, '')}`}
title={intl.formatMessage(messages.call)}
>
{tel}
</a>
);
} else if (fax) {
ret_label = intl.formatMessage(messages.fax);
ret = ReplacePhoneNumbers(fax, 'fax');
ret = (
<a
href={`fax:${fax.trim().replace(/|\/|\s/gm, '')}`}
title={intl.formatMessage(messages.call_fax)}
>
{fax}
</a>
);
} else if (email) {
ret_label = intl.formatMessage(messages.email_label);
ret = ReplaceEmails(email);
ret = (
<a
href={`mailto:${email.trim().replace(/|\/|\s/gm, '')}`}
title={intl.formatMessage(messages.write_to)}
>
{email}
</a>
);
}
ret_label = label ? <>{ret_label}: </> : null;
ret_label = label ? strong ? <strong>{ret_label}</strong> : ret_label : null;

return ret ? (
<>
{ret_label}
<span dangerouslySetInnerHTML={{ __html: ret }} />
<span>{ret}</span>
</>
) : null;
};
Expand Down
1 change: 1 addition & 0 deletions src/components/ItaliaTheme/View/Commons/SmallVenue.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO REMOVEME Sembra non più usato, rimuovere
import { useDispatch, useSelector } from 'react-redux';
import React, { useEffect } from 'react';
import { getContent } from '@plone/volto/actions';
Expand Down
1 change: 1 addition & 0 deletions src/components/ItaliaTheme/View/UOView/UOTelephones.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

// TODO REMOVEME Sembra non più usato, rimuovere
import { defineMessages, useIntl } from 'react-intl';
import { ContactLink } from 'design-comuni-plone-theme/components/ItaliaTheme/View';

Expand Down

0 comments on commit ff7bcab

Please sign in to comment.