Skip to content

Commit

Permalink
Merge pull request #1484 from greenbone/mergify/bp/master/pr-1482
Browse files Browse the repository at this point in the history
Fix "not regexp ..." filters (bp #1482)
  • Loading branch information
timopollmeier authored Apr 14, 2021
2 parents 4027473 + df06a8c commit 62420bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Improve modify_override errors, fix no NVT case [#1435](https://github.com/greenbone/gvmd/pull/1435)
- Fix size calculation in `--optimize vacuum` [#1447](https://github.com/greenbone/gvmd/pull/1447)
- Fix report host end time check in CVE scans [#1462](https://github.com/greenbone/gvmd/pull/1462)
- Fix "not regexp ..." filters [#1482](https://github.com/greenbone/gvmd/pull/1482)

### Removed

Expand Down
38 changes: 24 additions & 14 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -3732,20 +3732,30 @@ filter_clause (const char* type, const char* filter,

if (keyword_applies_to_column (keyword, filter_column)
&& select_column && column_type_matches)
g_string_append_printf (clause,
"%s"
"(%s IS NULL"
" OR CAST (%s AS TEXT)"
" NOT %s '%s%s%s')",
(index ? " AND " : ""),
select_column,
select_column,
last_was_re
? sql_regexp_op ()
: sql_ilike_op (),
last_was_re ? "" : "%%",
quoted_keyword,
last_was_re ? "" : "%%");
{
if (last_was_re)
g_string_append_printf (clause,
"%s"
"(%s IS NULL"
" OR NOT (CAST (%s AS TEXT)"
" %s '%s'))",
(index ? " AND " : ""),
select_column,
select_column,
sql_regexp_op (),
quoted_keyword);
else
g_string_append_printf (clause,
"%s"
"(%s IS NULL"
" OR CAST (%s AS TEXT)"
" NOT %s '%%%s%%')",
(index ? " AND " : ""),
select_column,
select_column,
sql_ilike_op (),
quoted_keyword);
}
else
g_string_append_printf (clause,
"%s t ()",
Expand Down

0 comments on commit 62420bd

Please sign in to comment.