Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILE-4624 format-text: Fix iframes with inline styles #4115

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/core/directives/format-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
* Apply CoreExternalContentDirective to a certain element.
*
* @param element Element to add the attributes to.
* @param onlyInlineStyles Whether to only handle inline styles.
* @returns External content instance or undefined if siteId is not provided.
*/
protected addExternalContent(element: Element): CoreExternalContentDirective | undefined {
protected addExternalContent(element: Element, onlyInlineStyles = false): CoreExternalContentDirective | undefined {
if (!this.siteId) {
return;
}
Expand All @@ -185,11 +186,13 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
extContent.url = element.getAttribute('src') ?? element.getAttribute('href') ?? element.getAttribute('xlink:href');
extContent.posterUrl = element.getAttribute('poster');

// Remove the original attributes to avoid performing requests to untreated URLs.
element.removeAttribute('src');
element.removeAttribute('href');
element.removeAttribute('xlink:href');
element.removeAttribute('poster');
if (!onlyInlineStyles) {
// Remove the original attributes to avoid performing requests to untreated URLs.
element.removeAttribute('src');
element.removeAttribute('href');
element.removeAttribute('xlink:href');
element.removeAttribute('poster');
}

extContent.ngAfterViewInit();

Expand Down Expand Up @@ -569,9 +572,9 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
// Handle inline styles.
elementsWithInlineStyles.forEach((el: HTMLElement) => {
// Only add external content for tags that haven't been treated already.
if (el.tagName != 'A' && el.tagName != 'IMG' && el.tagName != 'AUDIO' && el.tagName != 'VIDEO'
&& el.tagName != 'SOURCE' && el.tagName != 'TRACK') {
this.addExternalContent(el);
if (el.tagName !== 'A' && el.tagName !== 'IMG' && el.tagName !== 'AUDIO' && el.tagName !== 'VIDEO'
&& el.tagName !== 'SOURCE' && el.tagName !== 'TRACK' && el.tagName !== 'IMAGE') {
this.addExternalContent(el, true);
}
});

Expand Down