Skip to content

Commit

Permalink
Properly check if value is a URL
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Aug 29, 2024
1 parent ec882b8 commit 8acbdcc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { addFilter } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import isURLLike from '../components/link-control/is-url-like';
import { unlock } from '../lock-unlock';
import BlockContext from '../components/block-context';

Expand Down Expand Up @@ -176,14 +177,12 @@ export const withBlockBindingSupport = createHigherOrderComponent(
for ( const [ attributeName, value ] of Object.entries(
values
) ) {
if ( attributeName === 'url' ) {
if (
attributeName === 'url' &&
( ! value || ! isURLLike( value ) )
) {
// Return null if value is not a valid URL.
try {
new URL( value );
attributes[ attributeName ] = value;
} catch ( error ) {
attributes[ attributeName ] = null;
}
attributes[ attributeName ] = null;
} else {
attributes[ attributeName ] = value;
}
Expand Down

0 comments on commit 8acbdcc

Please sign in to comment.