Skip to content

Commit 1dd5adb

Browse files
committed
fix: embed running on all optimole URLs when not valid
1 parent dfc05fb commit 1dd5adb

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

assets/src/video-player/common/utils.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1+
const VIDEO_EXTENSIONS = [ 'mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv', 'm4v' ];
2+
3+
const hasVideoExtension = ( url ) => {
4+
try {
5+
const { pathname } = new URL( url );
6+
const extension = pathname.split( '.' ).pop()?.toLowerCase();
7+
return VIDEO_EXTENSIONS.includes( extension );
8+
} catch {
9+
return false;
10+
}
11+
};
12+
113
export const isOptimoleURL = async( url ) => {
214
const customEmbedRegexPattern = new RegExp( `^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*$` );
315

4-
if ( ! customEmbedRegexPattern.test( url ) ) {
16+
if ( ! customEmbedRegexPattern.test( url ) ) {
17+
return false;
18+
}
19+
20+
if ( ! hasVideoExtension( url ) ) {
521
return false;
622
}
723

@@ -12,6 +28,7 @@ export const isOptimoleURL = async( url ) => {
1228

1329
return contentType.includes( 'video' );
1430
}
31+
return false;
1532
} catch ( error ) {
1633
return false;
1734
}

assets/src/video-player/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ registerBlockVariation( 'core/embed', {
2929
return 'optimole' === blockAttributes.providerNameSlug;
3030
},
3131
patterns: [
32-
`^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*$`
32+
`^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*\\.(mp4|webm|ogg|mov|avi|mkv|m4v)$`
3333
]
3434
});
3535

0 commit comments

Comments
 (0)