This project is archived and is in readonly mode.

#6730 ✓committed
dvdplm

number_to_phone broken with empty number and area_code: true

Reported by dvdplm | April 20th, 2011 @ 03:12 PM

This raises a "TypeError Exception: can't convert nil into String" exception:

    number_to_phone "", area_code: true

These both work (returns ""):

    number_to_phone "", area_code: false
    number_to_phone ""

The reason for the exception is that the #gsub! on line 73 of actionpack/lib/action_view/helpers/number_helper.rb returns nil when there is no match and String#<< is called with a nil argument.

The fix is easy. Replace line 50:

    return nil if number.nil?

...with:

    return nil if number.blank?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages