Skip to content

Commit

Permalink
Fix word boundary check in Ticket::Number::{Date,Increment}#check
Browse files Browse the repository at this point in the history
  • Loading branch information
rlue committed Jun 23, 2018
1 parent df0b213 commit d6f1c3d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/models/ticket/number/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ def check(string)
end

# probe format
string.scan(/\b#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(\d{4,10}#{system_id}\d{2,40})\b/i) do
# NOTE: we use `(?<=\W|^)` at the start of the regular expressions below
# because `\b` fails when ticket_hook begins with a non-word character (like '#')
string.scan(/(?<=\W|^)#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(\d{4,10}#{system_id}\d{2,40})\b/i) do
ticket = Ticket.find_by(number: $1)
break if ticket
end
if !ticket
string.scan(/\b#{Regexp.quote(ticket_hook)}\s{0,2}(\d{4,10}#{system_id}\d{2,40})\b/i) do
string.scan(/(?<=\W|^)#{Regexp.quote(ticket_hook)}\s{0,2}(\d{4,10}#{system_id}\d{2,40})\b/i) do
ticket = Ticket.find_by(number: $1)
break if ticket
end
Expand Down
6 changes: 4 additions & 2 deletions app/models/ticket/number/increment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ def check(string)
end

# probe format
string.scan(/\b#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(#{system_id}\d{2,48})\b/i) do
# NOTE: we use `(?<=\W|^)` at the start of the regular expressions below
# because `\b` fails when ticket_hook begins with a non-word character (like '#')
string.scan(/(?<=\W|^)#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(#{system_id}\d{2,48})\b/i) do
ticket = Ticket.find_by(number: $1)
break if ticket
end
if !ticket
string.scan(/\b#{Regexp.quote(ticket_hook)}\s{0,2}(#{system_id}\d{2,48})\b/i) do
string.scan(/(?<=\W|^)#{Regexp.quote(ticket_hook)}\s{0,2}(#{system_id}\d{2,48})\b/i) do
ticket = Ticket.find_by(number: $1)
break if ticket
end
Expand Down

0 comments on commit d6f1c3d

Please sign in to comment.