File tree 2 files changed +45
-0
lines changed 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -819,6 +819,8 @@ export namespace entity {
819
819
return entityProto ;
820
820
821
821
function excludePathFromEntity ( entity : EntityProto , path : string ) {
822
+ if ( ! entity ) return ;
823
+
822
824
const arrayIndex = path . indexOf ( '[]' ) ;
823
825
const entityIndex = path . indexOf ( '.' ) ;
824
826
const wildcardIndex = path . indexOf ( '.*' ) ;
@@ -905,6 +907,7 @@ export namespace entity {
905
907
isFirstPathPartDefined
906
908
) {
907
909
const array = entity . properties ! [ firstPathPart ] . arrayValue ;
910
+ if ( ! array ) return ;
908
911
// eslint-disable-next-line @typescript-eslint/no-explicit-any
909
912
array . values . forEach ( ( value : any ) => {
910
913
if ( value . entityValue ) {
Original file line number Diff line number Diff line change @@ -1116,6 +1116,48 @@ describe('entity', () => {
1116
1116
expectedEntityProto
1117
1117
) ;
1118
1118
} ) ;
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
+ } ) ;
1119
1161
} ) ;
1120
1162
1121
1163
describe ( 'formatArray' , ( ) => {
You can’t perform that action at this time.
0 commit comments