Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

validates_uniqueness_of doesn't escape attributes

#23

Let's say I have a table with a column called 'key' (which is a SQL keyword). If I try and validate_uniqueness_of :key, the SQL query fails, since the attribute 'key' isn't escaped:

SELECT key FROM `api_tickets` WHERE (LOWER(`api_tickets`.key) = 'asdsd')

Should be:

SELECT `api_tickets`.key FROM `api_tickets` WHERE (LOWER(`api_tickets`.key) = 'asdsd')

Patch is attached.

Reported by Alex MacCaw · April 19th, 2008 @ 09:39 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Alex MacCaw
  2. Alex MacCaw
  3. Rick
    Rick

    It's not actually quoting the column name though, is it? It looks like it's only disambiguating the column name by adding the table name to it.

    April 19th, 2008 @ 04:28 PM

  4. Alex MacCaw
    Alex MacCaw

    That's right. I thought about escaping the column name, however I decided I'd follow the convention which seems to escape the table name, rather than the column name (and provides a ready method to do so).

    April 19th, 2008 @ 04:48 PM

  5. Frederick Cheung
    Frederick Cheung

    Surely you only need to escape the column name though (and could not escaping the column break things if it was called something like "foo from"?)

    April 19th, 2008 @ 07:54 PM

  6. Alex MacCaw
    Alex MacCaw

    I didn't know you could have spaces in column names - but if this is a problem then by all means just escape the column name.

    April 19th, 2008 @ 10:38 PM

  7. Michael Koziarski
    Michael Koziarski

    Yeah, this looks good to go if you could switch it to use quote_column_name instead of the table name, and upload the two patches into a single patch file. For instructions on using git-format-patch see http://www.tpope.net/rails-git-b...

    Nice find, and nice work.

    April 23rd, 2008 @ 09:23 AM

  8. DHH
    DHH
    • State changed from new to incomplete

    Change status to open when koz's suggestions are implemented.

    May 1st, 2008 @ 05:36 AM

  9. Alex MacCaw
  10. Alex MacCaw
    Alex MacCaw

    I don't think uploading a file to a ticket makes it go back into the feed. I've added the changes koz suggested and re-uploaded the patch (in Git's format).

    May 5th, 2008 @ 05:53 PM

  11. Michael Koziarski
    Michael Koziarski
    • State changed from incomplete to open

    May 5th, 2008 @ 09:18 PM

  12. Repository
    Repository
    • State changed from open to resolved

    (from [4cc594bd708df1ec67b61833493198ab0009c627]) Fix validates_uniqueness_of for SQL keywords [#23 state:resolved]

    Signed-off-by: Pratik Naik

    http://github.com/rails/rails/co...

    May 11th, 2008 @ 07:30 PM