Fix lbry:// URLs in iframes being broken by Safari (#1812)

When Safari parses lbry:// URLs, it breaks them as they are not
compliant with the RFC 3986 URI syntax. This causes iframes in text
posts which link to a lbry:// URL to not display on Safari.

Instead, just use the lbry:// URL matched from the iframe regex instead
of parsing the iframe on Safari.
This commit is contained in:
ktprograms 2022-07-07 22:39:10 +08:00 committed by GitHub
parent 54122f8998
commit fc32339d2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
// @flow
import { CHANNEL_STAKED_LEVEL_VIDEO_COMMENTS, MISSING_THUMB_DEFAULT } from 'config';
import { platform } from 'util/platform';
import { formattedEmote, inlineEmote } from 'util/remark-emote';
import { formattedLinks, inlineLinks } from 'util/remark-lbry';
import { formattedTimestamp, inlineTimestamp } from 'util/remark-timestamp';
@ -141,7 +142,7 @@ const schema = { ...defaultSchema };
schema.protocols.href.push('lbry');
schema.attributes.a.push('embed');
const REPLACE_REGEX = /(<iframe\s+src=["'])(.*?(?=))(["']\s*><\/iframe>)/g;
const REPLACE_REGEX = /(?:<iframe\s+src=["'])(.*?(?=))(?:["']\s*><\/iframe>)/g;
// ****************************************************************************
// ****************************************************************************
@ -162,7 +163,11 @@ export default React.memo<MarkdownProps>(function MarkdownPreview(props: Markdow
} = props;
const strippedContent = content
? content.replace(REPLACE_REGEX, (iframeHtml) => {
? content.replace(REPLACE_REGEX, (iframeHtml, iframeUrl) => {
if (platform.isSafari()) {
return iframeUrl;
}
// Let the browser try to create an iframe to see if the markup is valid
const outer = document.createElement('div');
outer.innerHTML = iframeHtml;