Skip to content

Commit

Permalink
MOBILE-4624 format-text: Fix iframes with inline styles
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Jul 8, 2024
1 parent 5b23097 commit 45a7681
Showing 1 changed file with 12 additions and 9 deletions.
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

0 comments on commit 45a7681

Please sign in to comment.