~cytrogen/masto-fe

55e7c08a83547424024bac311d5459cb82cf6dae — Claire 2 years ago a985d58
Fix verified badge in account lists potentially including rel="me" links (#25561)

1 files changed, 17 insertions(+), 1 deletions(-)

M app/javascript/mastodon/components/verified_badge.tsx
M app/javascript/mastodon/components/verified_badge.tsx => app/javascript/mastodon/components/verified_badge.tsx +17 -1
@@ 1,11 1,27 @@
import { Icon } from './icon';

const domParser = new DOMParser();

const stripRelMe = (html: string) => {
  const document = domParser.parseFromString(html, 'text/html').documentElement;

  document.querySelectorAll<HTMLAnchorElement>('a[rel]').forEach((link) => {
    link.rel = link.rel
      .split(' ')
      .filter((x: string) => x !== 'me')
      .join(' ');
  });

  const body = document.querySelector('body');
  return body ? { __html: body.innerHTML } : undefined;
};

interface Props {
  link: string;
}
export const VerifiedBadge: React.FC<Props> = ({ link }) => (
  <span className='verified-badge'>
    <Icon id='check' className='verified-badge__mark' />
    <span dangerouslySetInnerHTML={{ __html: link }} />
    <span dangerouslySetInnerHTML={stripRelMe(link)} />
  </span>
);