Skip to content

String#titleize doesn't work properly with smart quotes #5584

Closed
jfi opened this Issue Mar 26, 2012 · 0 comments

2 participants

@jfi
jfi commented Mar 26, 2012

Where smart quotes are used instead of apostrophes in a string, String.titleize will capitalise the letters following the quote.

1.9.3-p0 :001 > str = "Fred's"
=> "Fred's"
1.9.3-p0 :002 > str.titleize
=> "Fred's"
1.9.3-p0 :003 > str = "Fred’s"
=> "Fred’s"
1.9.3-p0 :004 > str.titleize
=> "Fred’S"

I'm using the following ActiveSupport::Inflector::titleize method to fix this.

    def titleize(word)
      humanize(underscore(word)).gsub(/\b(['’]?[a-z])/u) { $1.capitalize }
    end
@drogus drogus closed this Mar 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.