Chatwoot/lib/regex_helper.rb
Sojan Jose 6cfd594d85
fix: flaky test whatsapp_cloud_service_spec.rb:17 (#5786)
Fix flaky test: flaky /spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb:17

example build: https://app.circleci.com/pipelines/github/chatwoot/chatwoot/48955/workflows/a2959d25-19ea-4812-ba15-5aac69c43265/jobs/49523

Cause: factory bot can create phone numbers of length 15 digits, which is valid e164, while our regex only handled up to 14 digits
2022-11-01 19:51:42 -07:00

13 lines
625 B
Ruby

module RegexHelper
# user https://rubular.com/ to quickly validate your regex
# the following regext needs atleast one character which should be
# valid unicode letter, unicode number, underscore, hyphen
# shouldn't start with a underscore or hyphen
UNICODE_CHARACTER_NUMBER_HYPHEN_UNDERSCORE = Regexp.new('\A[\p{L}\p{N}]+[\p{L}\p{N}_-]+\Z')
MENTION_REGEX = Regexp.new('\[(@[\w_. ]+)\]\(mention://(?:user|team)/\d+/(.*?)+\)')
TWILIO_CHANNEL_SMS_REGEX = Regexp.new('^\+\d{1,15}\z')
TWILIO_CHANNEL_WHATSAPP_REGEX = Regexp.new('^whatsapp:\+\d{1,15}\z')
WHATSAPP_CHANNEL_REGEX = Regexp.new('^\d{1,15}\z')
end