Summary
The LinkAlternate constructor rejects link alternates when the name field is an empty string (""), even though empty strings are semantically equivalent to null (no name set).
Root Cause
In src/Domain/Value/LinkAlternate.php:41, the code checks:
if (null !== $values['name']) {
$name = TrimmedNonEmptyString::fromString(\$values['name'])->toString();
}
An empty string ("") passes the null check but then fails the TrimmedNonEmptyString validation, throwing:
Webmozart\\Assert\\InvalidArgumentException: Expected a different value than "".
Observed Impact
We've encountered this in development environment when certain link alternates in Storyblok have empty strings instead of null for the name field. This causes the entire Links API response to fail during deserialization, blocking page rendering until the data is corrected or the library is patched.
Suggested Fix
Use !empty($values['name']) instead of null !== $values['name'] to treat empty strings and null identically:
if (!empty($values['name'])) {
$name = TrimmedNonEmptyString::fromString($values['name'])->toString();
}
This approach is consistent with how other optional fields like anchor are handled (line 111), which already guards against both null and empty strings.
Why This Matters
From a data resilience perspective, it makes sense to treat empty strings and null the same way for optional fields. Storyblok may legitimately return either representation, and the client library should gracefully handle both without throwing exceptions.
Thanks for maintaining this library! 🙏
Summary
The
LinkAlternateconstructor rejects link alternates when thenamefield is an empty string (""), even though empty strings are semantically equivalent tonull(no name set).Root Cause
In
src/Domain/Value/LinkAlternate.php:41, the code checks:An empty string (
"") passes thenullcheck but then fails theTrimmedNonEmptyStringvalidation, throwing:Observed Impact
We've encountered this in development environment when certain link alternates in Storyblok have empty strings instead of
nullfor thenamefield. This causes the entire Links API response to fail during deserialization, blocking page rendering until the data is corrected or the library is patched.Suggested Fix
Use
!empty($values['name'])instead ofnull !== $values['name']to treat empty strings and null identically:This approach is consistent with how other optional fields like
anchorare handled (line 111), which already guards against bothnulland empty strings.Why This Matters
From a data resilience perspective, it makes sense to treat empty strings and null the same way for optional fields. Storyblok may legitimately return either representation, and the client library should gracefully handle both without throwing exceptions.
Thanks for maintaining this library! 🙏