Skip to content

Commit

Permalink
Core Data: Check for presence of entity config before testing plural …
Browse files Browse the repository at this point in the history
…form. (#39476)

When auto-generating method names for various entities in the data system we
want to use manually-listed plural forms if they exist.

Previously, however, we've been assuming that when we search for an entity's
config that it exists. While this probably hasn't been a real source of bugs
it does present an opportunity for an invalid-type runtime exception.

In this patch we're verifying that the config exists before we access the
`plural` property, eliminating the opportunity for the rutnime crash.
  • Loading branch information
dmsnell authored Mar 16, 2022
1 parent 270320f commit 70f6f19
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export const getMethodName = (
const nameSuffix =
upperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );
const suffix =
usePlural && entityConfig.plural
usePlural && entityConfig?.plural
? upperFirst( camelCase( entityConfig.plural ) )
: nameSuffix;
return `${ prefix }${ kindPrefix }${ suffix }`;
Expand Down

0 comments on commit 70f6f19

Please sign in to comment.