sstephenson / global_phone

Parse, validate, and format phone numbers in Ruby using Google's libphonenumber database
MIT License
549 stars 104 forks source link

leadingDigits dbgen - busted #12

Closed gurgeous closed 8 years ago

gurgeous commented 10 years ago

There's a fairly serious bug in the db generator. Some of the elements have multiple children. When nodes.text is called in text_or_nil they end up getting concatenated together, which obviously isn't correct. See Korea (KR) for an example. I don't have the full pull request but you can fix this by adding something like this to database_generator.rb:

      def leadingDigits(node)
        nodes = node.search("leadingDigits")
        case nodes.length
        when 0 # nop
        when 1
          nodes.text
        else
          nodes.map { |i| "(?:#{i.text)})" }.join("|")
        end
      end

Not sure if this is the fix you're looking for, but it's definitely an issue. I'm happy to put together a full pull request if there's interest in this fix.

eileencodes commented 8 years ago

I know this was a long time ago so you've probably found a way around using this gem - but if you are still using it can you write a failing test case so I can better understand the issue? I'll reopen if I have a way of reproducing this or you want to open a PR.