File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -819,6 +819,8 @@ export namespace entity {
819819 return entityProto ;
820820
821821 function excludePathFromEntity ( entity : EntityProto , path : string ) {
822+ if ( ! entity ) return ;
823+
822824 const arrayIndex = path . indexOf ( '[]' ) ;
823825 const entityIndex = path . indexOf ( '.' ) ;
824826 const wildcardIndex = path . indexOf ( '.*' ) ;
@@ -905,6 +907,7 @@ export namespace entity {
905907 isFirstPathPartDefined
906908 ) {
907909 const array = entity . properties ! [ firstPathPart ] . arrayValue ;
910+ if ( ! array ) return ;
908911 // eslint-disable-next-line @typescript-eslint/no-explicit-any
909912 array . values . forEach ( ( value : any ) => {
910913 if ( value . entityValue ) {
Original file line number Diff line number Diff line change @@ -1116,6 +1116,48 @@ describe('entity', () => {
11161116 expectedEntityProto
11171117 ) ;
11181118 } ) ;
1119+
1120+ it ( 'should not throw when `null` value is supplied for a field with an entity/array index exclusion' , ( ) => {
1121+ const entityObject = {
1122+ excludeFromIndexes : [
1123+ 'entityCompletelyExcluded.*' ,
1124+ 'entityPropertyExcluded.name' ,
1125+ 'entityArrayCompletelyExcluded[].*' ,
1126+ 'entityArrayPropertyExcluded[].name' ,
1127+ ] ,
1128+
1129+ data : {
1130+ entityCompletelyExcluded : null ,
1131+ entityPropertyExcluded : null ,
1132+ entityArrayCompletelyExcluded : null ,
1133+ entityArrayPropertyExcluded : null ,
1134+ } ,
1135+ } ;
1136+
1137+ const expectedEntityProto = {
1138+ key : null ,
1139+ properties : {
1140+ entityCompletelyExcluded : {
1141+ nullValue : 0 ,
1142+ excludeFromIndexes : true ,
1143+ } ,
1144+ entityPropertyExcluded : {
1145+ nullValue : 0 ,
1146+ } ,
1147+ entityArrayCompletelyExcluded : {
1148+ nullValue : 0 ,
1149+ } ,
1150+ entityArrayPropertyExcluded : {
1151+ nullValue : 0 ,
1152+ } ,
1153+ } ,
1154+ } ;
1155+
1156+ assert . deepStrictEqual (
1157+ testEntity . entityToEntityProto ( entityObject ) ,
1158+ expectedEntityProto
1159+ ) ;
1160+ } ) ;
11191161 } ) ;
11201162
11211163 describe ( 'formatArray' , ( ) => {
You can’t perform that action at this time.
0 commit comments