Fix word boundary check in Ticket::Number::{Date,Increment}#check

This commit is contained in:
Ryan Lue 2018-06-22 18:38:56 +08:00
parent df0b213691
commit d6f1c3d9ec
2 changed files with 8 additions and 4 deletions

View file

@ -86,12 +86,14 @@ module Ticket::Number::Date
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

View file

@ -83,12 +83,14 @@ module Ticket::Number::Increment
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