Skip to content

Commit 8f9612e

Browse files
authored
Merge pull request #1591 from craftcms/bugfix/1560-setEmptyValue-and-normalizing-values
ensure normalised empty value is returned as an empty string
2 parents fe108ef + 9f4838e commit 8f9612e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/fields/DefaultField.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ public function parseField(): mixed
6565
$value = $this->field->normalizeValue($value);
6666
}
6767

68-
// if we're setting empty values and the value is an empty string - return it
68+
// if we're setting empty values and the value is empty - return an empty string
6969
// otherwise HtmlField will serialize it to null, and we setEmptyValues won't take effect
7070
// https://github.com/craftcms/feed-me/issues/1321
71-
if ($this->feed['setEmptyValues'] === 1 && $value === '') {
72-
return $value;
71+
// if the normalizeValue above returns null, which can happen for e.g. plain text field and a value of a single space
72+
// we also need to ensure that an empty string is returned, not the value as that can be null after normalization
73+
// https://github.com/craftcms/feed-me/issues/1560
74+
if ($this->feed['setEmptyValues'] === 1 && empty($value)) {
75+
return '';
7376
}
7477

7578
// Lastly, get each field to prepare values how they should

0 commit comments

Comments
 (0)