let browser validate iframe markup

This commit is contained in:
Sean Yesmunt 2020-04-29 17:37:14 -04:00
parent 1a50e697ce
commit 9923df7b19
2 changed files with 17 additions and 4 deletions

View file

@ -80,13 +80,26 @@ const schema = { ...defaultSchema };
schema.protocols.href.push('lbry'); schema.protocols.href.push('lbry');
schema.attributes.a.push('embed'); schema.attributes.a.push('embed');
const REPLACE_REGEX = /(<iframe src=")(.*?(?=))("><\/iframe>)/g; const REPLACE_REGEX = /(<iframe\s+src=["'])(.*?(?=))(["']\s*><\/iframe>)/g;
const MarkdownPreview = (props: MarkdownProps) => { const MarkdownPreview = (props: MarkdownProps) => {
const { content, strip, promptLinks } = props; const { content, strip, promptLinks } = props;
const strippedContent = content const strippedContent = content
? content.replace(REPLACE_REGEX, (x, y, iframeSrc) => { ? content.replace(REPLACE_REGEX, (iframeHtml, y, iframeSrc) => {
return `${iframeSrc}?embed=true`; // Let the browser try to create an iframe to see if the markup is valid
const outer = document.createElement('div');
outer.innerHTML = iframeHtml;
const iframe = ((outer.querySelector('iframe'): any): ?HTMLIFrameElement);
if (iframe) {
const src = iframe.src;
if (src && src.startsWith('lbry://')) {
return `${src}?embed=true`;
}
}
return iframeHtml;
}) })
: ''; : '';

View file

@ -50,7 +50,7 @@ class ModalPublishSuccess extends React.PureComponent<Props> {
</React.Fragment> </React.Fragment>
} }
actions={ actions={
<div className="card__actions"> <div className="section__actions">
<Button <Button
button="primary" button="primary"
label={__('View My Publishes')} label={__('View My Publishes')}