Skip to content
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

Path skipping due to undefined or empty values causes incorrect refIndex calculation #786

Open
1 of 2 tasks
tugkanpilka opened this issue Nov 27, 2024 · 0 comments
Open
1 of 2 tasks
Labels

Comments

@tugkanpilka
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

When the path in the get function has values that are empty or undefined, the subsequent paths' values are incorrectly computed due to wrong index calculations. This issue causes the function to return incorrect values and doesn't handle the skipping of such paths effectively.

The Fuse.js version where this bug is happening.

6.6.2

Is this a regression?

  • This is a regression bug

Which version did this behavior use to work in?

None

Steps To Reproduce

  1. Create an object with nested properties, some of which are undefined or empty.
  2. Call the fuse.search.

Example test case:

describe('Recurse into objects in arrays with null object in array', () => {
  const customSearchCase =[
    {
      "blocks": [
        {
          "id": "cd091ca6-a039-4e93-b510-3637f9cb6e3d",
          "type": "paragraph",
          "props": {
            "textColor": "default",
            "backgroundColor": "default",
            "textAlignment": "left"
          },
          "content": [
            {
              "type": "text",
              "text": "This content has a text.",
              "styles": {}
            }
          ],
          "children": []
        },
        {
          "id": "e78f03d7-db8f-4024-a0d0-269990a23fae",
          "type": "checkListItem",
          "props": {
            "textColor": "default",
            "backgroundColor": "default",
            "textAlignment": "left",
            "checked": false
          },
          "content": [
            {
              "type": "text",
              "text": "This content has a text 2",
              "styles": {}
            }
          ],
          "children": []
        },
        {
          "id": "e723f652-bbd7-49c6-96c1-41790b43616f",
          "type": "paragraph",
          "props": {
            "textColor": "default",
            "backgroundColor": "default",
            "textAlignment": "left"
          },
          "content": [],
          "children": []
        },
        {
          "id": "3d30ea0d-59a6-4595-bff5-223c307924ef",
          "type": "checkListItem",
          "props": {
            "textColor": "default",
            "backgroundColor": "default",
            "textAlignment": "left",
            "checked": false
          },
          "content": [
            {
              "type": "text",
              "text": "This content will be have wrong refIndex.",
              "styles": {}
            }
          ],
          "children": []
        },
      ],
      "fileName": "2024-11-25.md"
    },
  ]
  const customOptions = {
    keys: ['blocks.content.text'],
    threshold: 0.4,
    includeMatches: true,
  }
  let fuse
  beforeEach(() => (fuse = setup(customSearchCase, customOptions)))

  describe('When searching nested empty path', () => {
    let result
    beforeEach(() => (result = fuse.search('This content will be have wrong refIndex')))

    test('Result content refIndex must be 4', () => {
      const refIndex = result[0].matches[0].refIndex;
      expect(refIndex).eq(4)
    })
  })
})
  

Expected behavior

Modify the deepGet function to account for undefined or empty path values without skipping them. This involves adjusting the index management logic to ensure it tracks paths correctly even when encountering undefined or empty values.

Screenshots

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant