From d94c8811553c2b1e19e4f39625679c2233e0640f Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 16 Feb 2024 11:07:04 -0300 Subject: [PATCH] Trims url data to avoid errors due to blank space. --- .../components/metadata-types/url/class-tainacan-url.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/views/admin/components/metadata-types/url/class-tainacan-url.php b/src/views/admin/components/metadata-types/url/class-tainacan-url.php index 4b769cf06..e05e123bb 100644 --- a/src/views/admin/components/metadata-types/url/class-tainacan-url.php +++ b/src/views/admin/components/metadata-types/url/class-tainacan-url.php @@ -182,6 +182,8 @@ class URL extends Metadata_Type { // Empty strings are valid if ( !empty($url_value) ) { + $url_value = trim($url_value); + // If this seems to be a markdown link, we check if the url inside it is ok as well if ( !preg_match($reg_url, $url_value) && !preg_match($reg_full, $url_value) ) { $this->add_error( sprintf( __('"%s" is invalid. Please provide a valid, full URL or a Markdown link in the form of [label](url).', 'tainacan'), $url_value ) ); @@ -196,6 +198,8 @@ class URL extends Metadata_Type { // Empty strings are valid if ( !empty($value) ) { + $value = trim($value); + // If this seems to be a markdown link, we check if the url inside it is ok as well if ( !preg_match($reg_url, $value) && !preg_match($reg_full, $value) ) { $this->add_error( sprintf( __('"%s" is invalid. Please provide a valid, full URL or a Markdown link in the form of [label](url).', 'tainacan'), $value ) );