Skip to content

Commit

Permalink
add Regexp timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueFlaaa committed Oct 7, 2024
1 parent d697625 commit bd8c015
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/worldwide/phone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,19 @@ def split_extension(input)
number = input.downcase

["ext", "x", ";"].each do |separator|
if number.include?(separator)
m = number.match(Regexp.new("(?<base>[0-9a-z +-]*)\\s*#{separator}\\.?\\s*(?<ext>.*)"))
return [m["base"], m["ext"]] unless m.nil?
end
next unless number.include?(separator)

m = number.match(Regexp.new(
"(?<base>[0-9a-z +-]*)\\s*#{separator}\\.?\\s*(?<ext>.*)",
timeout: 1,
))
return [m["base"], m["ext"]] unless m.nil?
end

# If we get this far, then we have not found an extension, and assume that the full input is just a public number
[input, nil]
rescue Regexp::TimeoutError
[input, nil]
end

# Convert exotic characters to ASCII
Expand Down

0 comments on commit bd8c015

Please sign in to comment.