performant-software / react-components

A library of shared React components
https://performant-software.github.io/react-components/
MIT License
1 stars 1 forks source link

`getFieldId` in `TypesenseUtils` truncates the last character of each field name #280

Closed camdendotlol closed 3 months ago

camdendotlol commented 3 months ago

I was looking into why labels weren't working in Sapientia and noticed that the UUIDs FacetListsGrouped was passing to my resolveLabel prop were missing their final character. Going up the stack to react-components, I think I found where the issue is coming from.

getFieldId uses the substring method to separate a field UUID from its parent model's UUID:

  if (value.includes(ATTRIBUTE_DELIMITER)) {
    value = value.substring(value.indexOf(ATTRIBUTE_DELIMITER) + 1, value.length - 1);
  }

The substring here ends at value.length - 1. This would be the correct way to look up the last item in an array by index, but substring's second argument is exclusive, not inclusive, so the string slice stops before value.length - 1, leaving off the last character.

Correcting this bug should be as simple as changing value.length - 1 to just value.length.

(See https://github.com/performant-software/react-components/blob/master/packages/core-data/src/utils/Typesense.js#L110)