Skip to content

Commit

Permalink
fix: not check sub-property existence for null values (#1330)
Browse files Browse the repository at this point in the history
Co-authored-by: danieljbruce <[email protected]>
  • Loading branch information
mrnagydavid and danieljbruce authored Nov 20, 2024
1 parent ea17528 commit 5c0ddbc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ export namespace entity {
return entityProto;

function excludePathFromEntity(entity: EntityProto, path: string) {
if (!entity) return;

const arrayIndex = path.indexOf('[]');
const entityIndex = path.indexOf('.');
const wildcardIndex = path.indexOf('.*');
Expand Down Expand Up @@ -905,6 +907,7 @@ export namespace entity {
isFirstPathPartDefined
) {
const array = entity.properties![firstPathPart].arrayValue;
if (!array) return;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
array.values.forEach((value: any) => {
if (value.entityValue) {
Expand Down
42 changes: 42 additions & 0 deletions test/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,48 @@ describe('entity', () => {
expectedEntityProto
);
});

it('should not throw when `null` value is supplied for a field with an entity/array index exclusion', () => {
const entityObject = {
excludeFromIndexes: [
'entityCompletelyExcluded.*',
'entityPropertyExcluded.name',
'entityArrayCompletelyExcluded[].*',
'entityArrayPropertyExcluded[].name',
],

data: {
entityCompletelyExcluded: null,
entityPropertyExcluded: null,
entityArrayCompletelyExcluded: null,
entityArrayPropertyExcluded: null,
},
};

const expectedEntityProto = {
key: null,
properties: {
entityCompletelyExcluded: {
nullValue: 0,
excludeFromIndexes: true,
},
entityPropertyExcluded: {
nullValue: 0,
},
entityArrayCompletelyExcluded: {
nullValue: 0,
},
entityArrayPropertyExcluded: {
nullValue: 0,
},
},
};

assert.deepStrictEqual(
testEntity.entityToEntityProto(entityObject),
expectedEntityProto
);
});
});

describe('formatArray', () => {
Expand Down

0 comments on commit 5c0ddbc

Please sign in to comment.