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

[BUG] Search with operators in the interactive interface #2153

Open
FlorianTrigodet opened this issue Oct 23, 2023 · 5 comments
Open

[BUG] Search with operators in the interactive interface #2153

FlorianTrigodet opened this issue Oct 23, 2023 · 5 comments
Assignees

Comments

@FlorianTrigodet
Copy link
Contributor

Short description of the problem

In the interactive interface, we can search for items matching an operator formula. And it does not work with large numbers somewhat.

anvi'o version

anvi'o v8

Detailed description of the issue

With this table:
toto.txt

anvi-interactive --manual -d toto.txt -p PROFILE.db

The search works when I search for values > 70,000:
Screenshot 2023-10-23 at 15 45 22

But it fails when I search for values > 2,000,000, it reports too many things including values not matching my condition?:
Screenshot 2023-10-23 at 15 45 36

No idea what is happing here 🤷

@meren
Copy link
Member

meren commented Oct 23, 2023

lol. weird indeed.

@metehaansever, can you please take a look at this?

@Ge0rges
Copy link
Collaborator

Ge0rges commented Mar 25, 2024

@FlorianTrigodet @metehaansever I was looking into this but couldn't reproduce it, has it been fixed and/or can you reproduce it?

@Ge0rges
Copy link
Collaborator

Ge0rges commented Mar 25, 2024

I will say that generally though something like this would be cleaner/safer than eval():

function evaluateCondition(cellValue, searchValue, operator, operatorText) {
    switch (operator) {
        case '0': // "=="
            return cellValue.toString() === searchValue;
        case '1': // "!="
            return cellValue.toString() !== searchValue;
        case '2': // ">"
            return parseFloat(cellValue) > parseFloat(searchValue);
        case '3': // "<"
            return parseFloat(cellValue) < parseFloat(searchValue);
        case '4': // ">="
            return parseFloat(cellValue) >= parseFloat(searchValue);
        case '5': // "<="
            return parseFloat(cellValue) <= parseFloat(searchValue);
        case '6': // "contains"
            return cellValue.toString().toLowerCase().includes(searchValue.toLowerCase());
        default:
            return; // or throw an error
    }
}

@meren
Copy link
Member

meren commented Mar 26, 2024

Absolutely -- No eval's should ever come close to anywhere near user-provided data.

@metehaansever
Copy link
Contributor

I realized that using the Eval function posed significant problems, so I replaced it with Function(). However, this didn't resolve the issue. I believe we should reconsider the entire structure from the ground up.

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

4 participants