From 8acbdcc69c01086d82ec875bcee0525a7001d0f2 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Thu, 29 Aug 2024 19:14:28 +0200 Subject: [PATCH] Properly check if value is a URL --- .../src/hooks/use-bindings-attributes.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/hooks/use-bindings-attributes.js b/packages/block-editor/src/hooks/use-bindings-attributes.js index 3ff5ea03ec01ab..e1ebf5fda6b8ee 100644 --- a/packages/block-editor/src/hooks/use-bindings-attributes.js +++ b/packages/block-editor/src/hooks/use-bindings-attributes.js @@ -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'; @@ -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; }