dice icon indicating copy to clipboard operation
dice copied to clipboard

Improve `WildCardMatch` function to handle edge cases in the `regex` package

Open iamanjali1003 opened this issue 1 year ago • 4 comments

Description

The current implementation of the WildCardMatch function in the regex package works well for many scenarios, but there are several edge cases that need to be addressed to ensure robustness. Below are the identified edge cases:

  1. Empty Strings:
    • Both pattern and key are empty.
    • pattern is empty, but key is not.
    • key is empty, but pattern is not.
  2. Only Wildcards:
    • pattern consists only of `` characters.
    • pattern consists only of ? characters.

Examples

  • pattern = ""key = "" (should return true).
  • pattern = "*"key = "anything" (should return true).

Suggested Improvements

  • Add checks and logic to handle the above edge cases.
  • Write unit tests to cover these scenarios.

iamanjali1003 avatar Oct 01 '24 17:10 iamanjali1003

@iamanjali1003 can you please add details around which repo and file these changes are for? Also add few examples by execution for reference.

lucifercr07 avatar Oct 01 '24 17:10 lucifercr07

@lucifercr07 I am referring to the code found here: https://github.com/DiceDB/dice/blob/master/internal/regex/regex.go, specifically the WildCardMatch function. We are using this function here: https://github.com/DiceDB/dice/blob/master/internal/sql/executor.go#L467.

iamanjali1003 avatar Oct 01 '24 17:10 iamanjali1003

cc: @JyotinderSingh for reference.

lucifercr07 avatar Oct 01 '24 17:10 lucifercr07

@lucifercr07 / @iamanjali1003 - can this task be assigned to me

sahoss avatar Oct 06 '24 12:10 sahoss