This project is archived and is in readonly mode.

#2653 ✓committed
Jacob Burkhart

validates_uniqueness_of unicode aware field length

Reported by Jacob Burkhart | May 15th, 2009 @ 06:27 PM | in 2.3.4

If I have a validates_uniqueness_of column with limit 50 and set it to:

ᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉ

rails incorrectly runs a check for anything existing where that column equals

ᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈᏉᏊᏈ?

The problem is in validates_uniqueness_of string concatenation (implemented in #1042)

http://github.com/rails/rails/blob/b6bac73b282c7e500c43810f2a937fc0...

value = column.limit ? value.to_s[0, column.limit] : value.to_s

should be changed to

value = column.limit ? value.to_s.mb_chars[0, column.limit].to_s : value.to_s

NOTE: also to reproduce you must have set encoding: utf8 in database.yml, and your database table must be "convert to character set utf8"

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>

Referenced by

Pages