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

fix notcontains search option operator #18003

Open
wants to merge 1 commit into
base: 10.0/bugfixes
Choose a base branch
from

Conversation

btry
Copy link
Contributor

@btry btry commented Oct 3, 2024

SQL requests are wrong when using a search criteria with the operator notcontains.

It seems there is no unit tests for this, then I added them.

To reproduce

Need to find a search option having datatype = number without min nor max boundaries. Printer current count of page is an easy to test candidate.

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

The variable $nott is used later in Search::addWhere() leading to a double negation. I de-factorized the code to fix the issue to stick in the same design as equals / notequals operators implementation.

Screenshots (if appropriate):

@btry btry force-pushed the fix_not_contains_search_operator branch from 008851d to 5bb30bc Compare October 3, 2024 18:55

// Potential negation will be handled by the subquery operator
$SEARCH = self::makeTextSearch($val, false);
$subquery_operator = $nott ? "IN" : "NOT IN";
Copy link
Contributor Author

@btry btry Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is inverted compared to "contains" counterpart a few lines below

tests/functional/Search.php Outdated Show resolved Hide resolved
@btry btry force-pushed the fix_not_contains_search_operator branch from 5bb30bc to d9f2d67 Compare October 3, 2024 18:59
@@ -4744,8 +4744,52 @@ public static function addWhere($link, $nott, $itemtype, $ID, $searchtype, $val,

switch ($searchtype) {
case "notcontains":
$nott = !$nott;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@btry btry changed the title fix notcontains search option fix notcontains search option operator Oct 3, 2024
@btry btry force-pushed the fix_not_contains_search_operator branch from 8e5cf01 to d9f2d67 Compare October 3, 2024 19:40
tests/functional/Search.php Outdated Show resolved Hide resolved
@btry btry force-pushed the fix_not_contains_search_operator branch from d9f2d67 to 6920525 Compare October 4, 2024 06:35
@btry btry force-pushed the fix_not_contains_search_operator branch from 6920525 to 4e89aa8 Compare October 4, 2024 06:37
@btry btry requested a review from trasher October 4, 2024 06:55
Copy link
Contributor

@trasher trasher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Search has always been opaque to my eyes, but added test seems OK.

Copy link
Member

@cedric-anne cedric-anne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating the whole case code, maybe it was possible to just adapt a few lines.

For instance:

if ($searchtype === 'contains') {
    $subquery_operator = $nott ? "NOT IN" : "IN";
} else {
    $subquery_operator = $nott ? "IN" : "NOT IN";
}

and

$SEARCH = self::makeTextSearch($val, $searchtype === 'contains' ? $nott : !$nott);

@btry
Copy link
Contributor Author

btry commented Oct 8, 2024

@cedric-anne

Yes, it would make sense. But I found there is a real mess with contains / notcontains on one hand and equals / not equals in the other hand. For numeric search options one or the other pair is used in function of the column being a ID or FK.
There are also many negations using $nott in case {...} structures which test table and column.

So I adopted the less risky solution, by reproducing the code pattern matching equals / not equals (which as far as I know is bug free).

Copy link

sonarcloud bot commented Oct 16, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
69.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

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

Successfully merging this pull request may close these issues.

3 participants