Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:valid key missing from @data instance variable #316

Open
butters-zeemee opened this issue Oct 8, 2024 · 3 comments
Open

:valid key missing from @data instance variable #316

butters-zeemee opened this issue Oct 8, 2024 · 3 comments

Comments

@butters-zeemee
Copy link

On version 0.9.4, when I run the following code:

p = Phonelib.parse('+14154055410')
p.valid?

an exception is raised with the following relevant backtrace:

*** NoMethodError Exception: undefined method `any?' for nil:NilClass

/usr/local/bundle/gems/phonelib-0.9.2/lib/phonelib/phone.rb:120:in `block in valid?'
/usr/local/bundle/gems/phonelib-0.9.2/lib/phonelib/phone.rb:120:in `select'
/usr/local/bundle/gems/phonelib-0.9.2/lib/phonelib/phone.rb:120:in `valid?'

Looking at the @data instance variable it appears that some of the values in that hash are missing the :valid key causing https://github.com/daddyz/phonelib/blob/master/lib/phonelib/phone.rb#L120C47-L120C64 to raise.

#<Phonelib::Phone:0x000055555f4594a8 @original="+14154055410", @extension="", @sanitized="14154055410", @original_s="+14154055410", @data={"AG"=>{:id=>"AG", :country_code=>"1", :leading_digits=>"268", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([457]\\d{6})$|1", :national_prefix_transform_rule=>"268\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :voip, :personal_number, :pager, :fixed_or_mobile]}, "AI"=>{:id=>"AI", :country_code=>"1", :leading_digits=>"264", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2457]\\d{6})$|1", :national_prefix_transform_rule=>"264\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :pager, :fixed_or_mobile]}, "AS"=>{:id=>"AS", :country_code=>"1", :leading_digits=>"684", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([267]\\d{6})$|1", :national_prefix_transform_rule=>"684\\1", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "BB"=>{:id=>"BB", :country_code=>"1", :leading_digits=>"246", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-9]\\d{6})$|1", :national_prefix_transform_rule=>"246\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :voip, :personal_number, :uan, :fixed_or_mobile]}, "BM"=>{:id=>"BM", :country_code=>"1", :leading_digits=>"441", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-9]\\d{6})$|1", :national_prefix_transform_rule=>"441\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "BS"=>{:id=>"BS", :country_code=>"1", :leading_digits=>"242", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([3-8]\\d{6})$|1", :national_prefix_transform_rule=>"242\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :uan, :fixed_or_mobile]}, "CA"=>{:id=>"CA", :country_code=>"1", :international_prefix=>"011", :national_prefix=>"1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :voip, :personal_number, :fixed_or_mobile]}, "DM"=>{:id=>"DM", :country_code=>"1", :leading_digits=>"767", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-7]\\d{6})$|1", :national_prefix_transform_rule=>"767\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "DO"=>{:id=>"DO", :country_code=>"1", :leading_digits=>"8001|8[024]9", :international_prefix=>"011", :national_prefix=>"1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "GD"=>{:id=>"GD", :country_code=>"1", :leading_digits=>"473", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-9]\\d{6})$|1", :national_prefix_transform_rule=>"473\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "GU"=>{:id=>"GU", :country_code=>"1", :leading_digits=>"671", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-9]\\d{6})$|1", :national_prefix_transform_rule=>"671\\1", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "JM"=>{:id=>"JM", :country_code=>"1", :leading_digits=>"658|876", :international_prefix=>"011", :national_prefix=>"1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "KN"=>{:id=>"KN", :country_code=>"1", :leading_digits=>"869", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-7]\\d{6})$|1", :national_prefix_transform_rule=>"869\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "KY"=>{:id=>"KY", :country_code=>"1", :leading_digits=>"345", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-9]\\d{6})$|1", :national_prefix_transform_rule=>"345\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :pager, :fixed_or_mobile]}, "LC"=>{:id=>"LC", :country_code=>"1", :leading_digits=>"758", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-8]\\d{6})$|1", :national_prefix_transform_rule=>"758\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "MP"=>{:id=>"MP", :country_code=>"1", :leading_digits=>"670", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-9]\\d{6})$|1", :national_prefix_transform_rule=>"670\\1", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "MS"=>{:id=>"MS", :country_code=>"1", :leading_digits=>"664", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([34]\\d{6})$|1", :national_prefix_transform_rule=>"664\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "PR"=>{:id=>"PR", :country_code=>"1", :leading_digits=>"787|939", :international_prefix=>"011", :national_prefix=>"1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "SX"=>{:id=>"SX", :country_code=>"1", :leading_digits=>"721", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"(5\\d{6})$|1", :national_prefix_transform_rule=>"721\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "TC"=>{:id=>"TC", :country_code=>"1", :leading_digits=>"649", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-479]\\d{6})$|1", :national_prefix_transform_rule=>"649\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :voip, :personal_number, :fixed_or_mobile]}, "TT"=>{:id=>"TT", :country_code=>"1", :leading_digits=>"868", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-46-8]\\d{6})$|1", :national_prefix_transform_rule=>"868\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :voicemail, :fixed_or_mobile]}, "US"=>{:id=>"US", :main_country_for_code=>"true", :country_code=>"1", :international_prefix=>"011", :national_prefix=>"1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :valid=>[:fixed_or_mobile], :possible=>[:premium_rate, :toll_free, :voip, :personal_number, :fixed_or_mobile]}, "VC"=>{:id=>"VC", :country_code=>"1", :leading_digits=>"784", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-7]\\d{6})$|1", :national_prefix_transform_rule=>"784\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :voip, :personal_number, :fixed_or_mobile]}, "VG"=>{:id=>"VG", :country_code=>"1", :leading_digits=>"284", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-578]\\d{6})$|1", :national_prefix_transform_rule=>"284\\1", :mobile_number_portable_region=>"true", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}, "VI"=>{:id=>"VI", :country_code=>"1", :leading_digits=>"340", :international_prefix=>"011", :national_prefix=>"1", :national_prefix_for_parsing=>"([2-9]\\d{6})$|1", :national_prefix_transform_rule=>"340\\1", :national=>"4154055410", :format=>{:pattern=>"(\\d{3})(\\d{3})(\\d{4})", :national_prefix_optional_when_formatting=>"true", :leading_digits=>"[2-9]", :format=>"($1) $2-$3", :intl_format=>"$1-$2-$3"}, :possible=>[:premium_rate, :toll_free, :personal_number, :fixed_or_mobile]}}, @national_number="4154055410">

I'm in the process of upgrading from version 0.7.7 and ran into this in a spec. Version 0.7.7 does not exhibit this behavior. In comparing the two branches I haven't been able to figure out where the :valid key is being removed in version 0.9.4. Is this a bug or am I using the library improperly?

@daddyz
Copy link
Owner

daddyz commented Oct 27, 2024

@butters-zeemee what is your ruby version?

@butters-zeemee
Copy link
Author

Sorry for neglecting to include that. I'm on version 2.6.6. Thank you for taking a look!

@daddyz
Copy link
Owner

daddyz commented Dec 16, 2024

@butters-zeemee I tried several ways to reproduce with no luck, can you try the latest version 0.10.3 and do you have anything in initializer for the gem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants