Skip to content

Commit

Permalink
Fixes zammad#3013 - Variables within Trigger and Scheduler behave dif…
Browse files Browse the repository at this point in the history
…ferently between subject and body
  • Loading branch information
mantas committed Nov 17, 2022
1 parent 52949c7 commit 8467685
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
18 changes: 7 additions & 11 deletions app/models/ticket/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@ def subject_build(subject, prefix_mode = nil)
def subject_clean(subject)
return '' if subject.blank?

ticket_hook = Setting.get('ticket_hook')
ticket_hook_divider = Setting.get('ticket_hook_divider')
ticket_hook = Regexp.escape Setting.get('ticket_hook')
ticket_hook_divider = Regexp.escape Setting.get('ticket_hook_divider')
ticket_subject_size = Setting.get('ticket_subject_size')

# remove all possible ticket hook formats with []
subject = subject.gsub(%r{\[#{ticket_hook}: #{number}\](\s+?|)}, '')
subject = subject.gsub(%r{\[#{ticket_hook}:#{number}\](\s+?|)}, '')
subject = subject.gsub(%r{\[#{ticket_hook}#{ticket_hook_divider}#{number}\](\s+?|)}, '')

# remove all possible ticket hook formats without []
subject = subject.gsub(%r{#{ticket_hook}: #{number}(\s+?|)}, '')
subject = subject.gsub(%r{#{ticket_hook}:#{number}(\s+?|)}, '')
subject = subject.gsub(%r{#{ticket_hook}#{ticket_hook_divider}#{number}(\s+?|)}, '')
# remove all possible ticket hook formats with [], () or without any wrapping
[ ['\[', '\]'], ['\(', '\)'], [''] ].each do |wrapping|
subject = subject
.gsub(%r{#{wrapping.first}#{ticket_hook}((: ?)|#{ticket_hook_divider})#{number}#{wrapping.last}(\s+?|)}, '')
end

# remove leading "..:\s" and "..[\d+]:\s" e. g. "Re: " or "Re[5]: "
subject = subject.gsub(%r{^(..(\[\d+\])?:\s)+}, '')
Expand Down
17 changes: 17 additions & 0 deletions spec/models/ticket/subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@
expect(ticket.subject_clean("something [Ticket##{ticket.number}]")).to eq('something')
end

it 'cleanup subject with regular ticket# in ()' do
expect(ticket.subject_clean("something (Ticket##{ticket.number})")).to eq('something')
end

it 'cleanup subject with ticket# with a colon' do
expect(ticket.subject_clean("something (Ticket#:#{ticket.number})")).to eq('something')
end

it 'cleanup subject with ticket# with a colon and space' do
expect(ticket.subject_clean("something (Ticket#: #{ticket.number})")).to eq('something')
end

it 'cleanup subject with ticket# with a custom divider' do
Setting.set('ticket_hook_divider', '---')
expect(ticket.subject_clean("something (Ticket#---#{ticket.number})")).to eq('something')
end

it 'cleanup subject with regular ticket# multiple time' do
expect(ticket.subject_clean("[Ticket##{ticket.number}] [Ticket##{ticket.number}] something [Ticket##{ticket.number}]")).to eq('something')
end
Expand Down

0 comments on commit 8467685

Please sign in to comment.