Skip to content

Commit

Permalink
Fixes #4948 - Trigger Condition "contains not" doesn't work correct i…
Browse files Browse the repository at this point in the history
…f "nil" is stored in the user object
  • Loading branch information
mantas authored and dominikklein committed Dec 27, 2023
1 parent aae2584 commit a81a25f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/selector/sql.rb
Expand Up @@ -464,7 +464,9 @@ def condition_sql(block_condition)
query << "#{attribute} #{like} (?)"
bind_params.push "%#{SqlHelper.quote_like(block_condition[:value])}%"
elsif block_condition[:operator] == 'contains not'
query << "#{attribute} NOT #{like} (?)"
# NOT LIKE is always false on NULL values
# https://github.com/zammad/zammad/issues/4948
query << "#{attribute} NOT #{like} (?) OR #{attribute} IS NULL"
bind_params.push "%#{SqlHelper.quote_like(block_condition[:value])}%"
elsif block_condition[:operator] == 'matches regex'
query << sql_helper.regex_match(attribute, negated: false)
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/selector/sql_spec.rb
Expand Up @@ -352,6 +352,25 @@ def get_condition(operator, range)

include_examples 'finds the ticket'
end

context 'with empty-looking values in DB' do
let(:value) { 'Some' }
let(:name) { 'ticket.note' }

before { ticket.update! note: database_value }

context 'when value is empty string' do
let(:database_value) { '' }

include_examples 'finds the ticket'
end

context 'when value is NULL' do
let(:database_value) { nil }

include_examples 'finds the ticket'
end
end
end

describe "operator 'is'" do
Expand Down

0 comments on commit a81a25f

Please sign in to comment.