Skip to content

Commit

Permalink
Embed: Fix Incorrect URL basename logic in EmbedPreview (WordPress#63052
Browse files Browse the repository at this point in the history
)


Co-authored-by: dhananjaykuber <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent 4d8f515 commit 2e27ad0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '@wordpress/block-editor';
import { Component } from '@wordpress/element';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { getAuthority } from '@wordpress/url';

/**
* Internal dependencies
Expand Down Expand Up @@ -73,14 +74,11 @@ class EmbedPreview extends Component {
const { interactive } = this.state;

const html = 'photo' === type ? getPhotoHtml( preview ) : preview.html;
const parsedHost = new URL( url ).host.split( '.' );
const parsedHostBaseUrl = parsedHost
.splice( parsedHost.length - 2, parsedHost.length - 1 )
.join( '.' );
const embedSourceUrl = getAuthority( url );
const iframeTitle = sprintf(
// translators: %s: host providing embed content e.g: www.youtube.com
__( 'Embedded content from %s' ),
parsedHostBaseUrl
embedSourceUrl
);
const sandboxClassnames = clsx(
type,
Expand Down Expand Up @@ -136,7 +134,7 @@ class EmbedPreview extends Component {
__(
"Embedded content from %s can't be previewed in the editor."
),
parsedHostBaseUrl
embedSourceUrl
) }
</p>
</Placeholder>
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/editor/various/embedding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test.describe( 'Embedding content', () => {
await expect(
currenEmbedBlock.locator( 'iframe' ),
'Valid embed. Should render valid element.'
).toHaveAttribute( 'title', 'Embedded content from twitter' );
).toHaveAttribute( 'title', 'Embedded content from twitter.com' );

await embedUtils.insertEmbed(
'https://twitter.com/wooyaygutenberg123454312'
Expand Down Expand Up @@ -150,7 +150,7 @@ test.describe( 'Embedding content', () => {
await expect(
currenEmbedBlock.locator( 'iframe' ),
'Photo content. Should render valid iframe element.'
).toHaveAttribute( 'title', 'Embedded content from cloudup' );
).toHaveAttribute( 'title', 'Embedded content from cloudup.com' );
} );

test( 'should allow the user to convert unembeddable URLs to a paragraph with a link in it', async ( {
Expand Down

0 comments on commit 2e27ad0

Please sign in to comment.