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

Possible case sensitivity "bug" #1

Open
tunelessly opened this issue May 30, 2023 · 0 comments
Open

Possible case sensitivity "bug" #1

tunelessly opened this issue May 30, 2023 · 0 comments

Comments

@tunelessly
Copy link

tunelessly commented May 30, 2023

Hello,

I'm developing an app that uses this library. I think I found a possible bug, or at the very least, a surprising (to me) behavior.

When computing the distance between two strings in case-insensitive mode, the highest match in my data set doesn't match what I expected. I looked at the code and the "problem" happens here - the inputs are being compared without regard for the user's selected settings.

Example

I've provided an example here - typescript playground.

Actual Behavior

jaroWinkler("haka", "Shakasi", {caseSensitive: false}); // ~0.857
jaroWinkler("haka", "Hakatiz", {caseSensitive: false}); // ~0.857 Expected this one to be equal to ~0.91
                                                        // since the prefixes match in case insensitive mode

Expected Behavior

jaroWinkler("haka", "Shakasi", {caseSensitive: false}); // ~0.857
jaroWinkler("haka", "Hakatiz", {caseSensitive: false}); // ~0.91

Workaround

Converting the strings to upper/lowercase ourselves avoids the issue entirely and results in the expected behavior:

jaroWinkler("haka", "Shakasi".toLowerCase()); // ~0.857
jaroWinkler("haka", "Hakatiz".toLowerCase()); // ~0.91

Potential "fix"

Before the loop in line 95, add the very same check that's present in the jaro function:

  if (options && !options.caseSensitive) {
    str1 = str1.toUpperCase();
    str2 = str2.toUpperCase();
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant