-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unescapeTerms/unescapeTerm: filter-out values of unexpected type #43728
unescapeTerms/unescapeTerm: filter-out values of unexpected type #43728
Conversation
Size Change: +10 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ping, @fullofcaffeine.
I can still see a similar error when following testing instructions from #40850.
I agree that we should make these utility methods resilient. But we should also fix the cause of the issue in the findOrCreateTerm
function. I had some notes for the latter and will try to do a follow-up in a separate PR.
Screenshot
Here's my follow-up - #43766. |
Ah, you're right, since |
What?
Filters out non-truthy values from the
terms
argument passed tounescapeTerms
. We're looking to filter outnull
andundefined
values from it, but we go a bit further: we actually check that the structural type of the value is correct and if it's not, we don't do anything meaning the function will returnundefined
- thisundefined
that is then filtered-out byunescapedTerms
.**Any other consuming code should take care handling a potential
undefined
value being returned fromunescapeTerm
.As a bonus, we replace lodash's
map
with the nativeArray.map
function.Why?
Even though it shouldn't receive an array with
undefined
(ornull
) values, we've seen instances of it around the code and when the value is finallymap
'ed to theunescapeTerm
function, it will fail with aTypeError: Cannot read properties of undefined (reading name)
because it expects an object of a certain structure, and ends up receiving something else (undefined
). See this issue: #40850.How?
We keep only truthy values in the
terms
array beforemap
ing them againstunescapeTerm
.Testing Instructions
TODO