Hello π , thanks for maintaining phonelib and regularly updating it!
I recently had to add some custom regular expressions to consider some phone numbers as valid which the library didn't consider as valid yet, but then ran into the error undefined method 'match' for nil:NilClass (NoMethodError).
Fetching gem metadata from https://rubygems.org/.
Fetching phonelib 0.9.3
Installing phonelib 0.9.3
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Hello, World!
+33 761234567 is valid: true
+213 551234567 is valid: true
Now comment the added regexes back in and run again. Here it might not be necessary because the numbers are already considered valid, but I just took some anonymous examples. Let's assume they aren't valid and the regexes are required. It leads to an error π΄ :
Fetching gem metadata from https://rubygems.org/.
Fetching phonelib 0.9.3
Installing phonelib 0.9.3
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Hello, World!
+33 761234567 is valid: true
/usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:216:in `block in number_format': undefined method `match' for nil:NilClass (NoMethodError)
national.match(cr("^(#{format[Core::LEADING_DIGITS]})"))) && \
^^^^^^
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:214:in `each'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:214:in `find'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:214:in `number_format'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:177:in `national_and_data'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:115:in `parse_single_country'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:133:in `block in detect_and_parse'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:131:in `each'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:131:in `each_with_object'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:131:in `detect_and_parse'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:50:in `analyze_single_country'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone_analyzer.rb:21:in `analyze'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/phone.rb:32:in `initialize'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/core.rb:414:in `new'
from /usr/local/bundle/gems/phonelib-0.9.3/lib/phonelib/core.rb:414:in `parse'
from app.rb:8:in `<main>'
The interesting part is that the error only happens for the second number, not the first one.
=> Is there some issue with the combination of the second regex with the second phone number? Or something else?
Hello π , thanks for maintaining phonelib and regularly updating it!
I recently had to add some custom regular expressions to consider some phone numbers as valid which the library didn't consider as valid yet, but then ran into the error
undefined method 'match' for nil:NilClass (NoMethodError)
.To reproduce, create the following files:
Gemfile:
(Or 0.10.1)
config/initializers/phone_lib.rb:
app.rb:
Then run (in Docker for reproducability independent of locally installed Ruby version):
docker run --rm -v $(pwd):/app -w /app ruby:3.2 bash -c 'bundle install && ruby app.rb'
Which works fine π’:
Now comment the added regexes back in and run again. Here it might not be necessary because the numbers are already considered valid, but I just took some anonymous examples. Let's assume they aren't valid and the regexes are required. It leads to an error π΄ :
The interesting part is that the error only happens for the second number, not the first one.
=> Is there some issue with the combination of the second regex with the second phone number? Or something else?