diff --git a/components/app/app/models/routing_parameters.rb b/components/app/app/models/routing_parameters.rb index 128ec2fc9..f9349abf2 100644 --- a/components/app/app/models/routing_parameters.rb +++ b/components/app/app/models/routing_parameters.rb @@ -14,7 +14,7 @@ def initialize(options) end def address - result = format_number(destination) + result = format_number(destination).gsub(/\D/, "") result = username.present? ? client_gateway_address(result) : public_gateway_address(result) result.prepend(dial_string_prefix) if dial_string_prefix.present? result.prepend("+") if plus_prefix @@ -24,7 +24,9 @@ def address def format_number(value) result = value.gsub(/\D/, "") result = Phony.format(result, format: :national, spaces: "") if national_dialing && Phony.plausible?(result) - result.gsub(/\D/, "") + result = result.gsub(/\D/, "") + result.prepend("+") if plus_prefix + result end private diff --git a/components/app/spec/models/dial_string_spec.rb b/components/app/spec/models/dial_string_spec.rb index 94a03c1ea..6717f72a1 100644 --- a/components/app/spec/models/dial_string_spec.rb +++ b/components/app/spec/models/dial_string_spec.rb @@ -109,7 +109,6 @@ expect(result).to eq("0716100987") end - it "formats a number in national format for countries without a trunk prefix" do dial_string = DialString.new( build_routing_parameters( @@ -122,17 +121,17 @@ expect(result).to eq("6505130514") end - it "formats a number in E.164 format" do dial_string = DialString.new( build_routing_parameters( - national_dialing: false + national_dialing: false, + plus_prefix: true ) ) result = dial_string.format_number("+855 (716)-100-987") - expect(result).to eq("855716100987") + expect(result).to eq("+855716100987") end end