Fixes #4948 - Trigger Condition "contains not" doesn't work correct if "nil" is stored in the user object

This commit is contained in:
Mantas 2023-12-27 12:19:24 +02:00 committed by Dominik Klein
parent aae2584b3f
commit a81a25fa6f
2 changed files with 22 additions and 1 deletions

View file

@ -464,7 +464,9 @@ class Selector::Sql < Selector::Base
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)

View file

@ -352,6 +352,25 @@ RSpec.describe Selector::Sql do
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