From 9f4838efab2402d5bb5a9be27d545377a281b69a Mon Sep 17 00:00:00 2001 From: i-just Date: Thu, 6 Feb 2025 08:48:16 +0000 Subject: [PATCH 1/2] ensure normalised empty value is returned as an empty string --- src/fields/DefaultField.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fields/DefaultField.php b/src/fields/DefaultField.php index c486ecd0..97e79e45 100644 --- a/src/fields/DefaultField.php +++ b/src/fields/DefaultField.php @@ -65,11 +65,14 @@ public function parseField(): mixed $value = $this->field->normalizeValue($value); } - // if we're setting empty values and the value is an empty string - return it + // if we're setting empty values and the value is empty - return an empty string // otherwise HtmlField will serialize it to null, and we setEmptyValues won't take effect // https://github.com/craftcms/feed-me/issues/1321 - if ($this->feed['setEmptyValues'] === 1 && $value === '') { - return $value; + // if the normalizeValue above returns null, which can happen for e.g. plain text field and a value of a single space + // we also need to ensure that an empty string is returned, not the value as that can be null after normalization + // https://github.com/craftcms/feed-me/issues/1560 + if ($this->feed['setEmptyValues'] === 1 && empty($value)) { + return ''; } // Lastly, get each field to prepare values how they should From cb16c76388c782ab87095d310b1fb8f1441301c7 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Thu, 6 Feb 2025 15:49:45 -0800 Subject: [PATCH 2/2] changelog for https://github.com/craftcms/feed-me/pull/1591 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b049b2..5ce94ced 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ - Feed Me settings are now only available to admins and when `allowAdminChanges` is set to `true`. ([#1581](https://github.com/craftcms/feed-me/pull/1581)) - Added support for `formatted` and `raw` subfields in the Google Maps plugin. ([#1587](https://github.com/craftcms/feed-me/pull/1587)) -- Fixed an issue where empty values were not respected for inner-element fields when `setEmptyValues` is set to `true`. ([#1590](https://github.com/craftcms/feed-me/pull/1590)) +- Fixed a bug where empty values were not respected for inner-element fields when `setEmptyValues` is set to `true`. ([#1590](https://github.com/craftcms/feed-me/pull/1590)) +- Fixed a bug where values with an empty string would not be treated as empty if `setEmtpyValues` is set to `true`. ([#1591](https://github.com/craftcms/feed-me/pull/1591)) ## 5.9.0 - 2024-11-26