Skip to content

Commit

Permalink
Merge pull request #1482 from timopollmeier/not-regexp-fix
Browse files Browse the repository at this point in the history
Fix "not regexp ..." filters
  • Loading branch information
bjoernricks authored Apr 13, 2021
2 parents 7a247db + 6019803 commit 256e5b4
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 @@ -22,6 +22,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 @@ -3794,20 +3794,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 256e5b4

Please sign in to comment.