Skip to content

Commit

Permalink
🐛 FIX: Re-fix coercion of empty strings to nulls on non-nullable, non…
Browse files Browse the repository at this point in the history
…-string fields
  • Loading branch information
michaelborn committed Feb 21, 2024
1 parent 22abed7 commit df2fd58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### 🐛 Fixed

- Fixes a regression on [OOE-26](https://ortussolutions.atlassian.net/browse/OOE-26) where empty string values are coerced to `NULL` when an ORM type *is* declared. Originally reported against `6.4.0`, resolved in `6.5.0`, then regressed in `6.5.1`. - Resolves [OOE-26](https://ortussolutions.atlassian.net/browse/OOE-26).

### 🔐 Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,13 @@ public static Object toHibernateValue( Component entity, Property property ) thr
String ormType = CommonUtil.toString( meta.get( CommonUtil.ORMTYPE, "" ) );
String fieldType = !ormType.trim().isEmpty() ? ormType : property.getType();

boolean isStringSafeField = ( fieldType == null || !fieldType.trim().isEmpty() || !CFConstants.STRINGLIKE_FIELDS.contains( fieldType ) );
boolean isStringSafeField = ( ormType == null || ormType.trim().isEmpty() || CFConstants.STRINGLIKE_FIELDS.contains( ormType ) );

// If the value is an empty string, and the field type is not "string-safe", coerce to a null.
if ( value instanceof String && ( ( String ) value ).trim().isEmpty() && !isStringSafeField ) {
logger.atDebug().log(
"toHibernateValue: Coercing {} property to a NULL, since the ORMtype [{}] or fieldType [{}] is not a string-safe field (one of [{}]",
property.getName(), ormType, fieldType, CFConstants.STRINGLIKE_FIELDS );
return null;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/models/KitchenSink.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ component persistent="true" {
ormtype="timestamp"
default="2023-07-29T04:56";

property
name ="expireDate"
notnull="false"
ormtype="timestamp"
default="";

this.name = "KitchenSink";

}

0 comments on commit df2fd58

Please sign in to comment.