ruby on rails - Coping with "string contains null byte" sent from users -


i have api controller receives information media file's path , id3 tags, , saves them active record instance, using postgresql/rails.

sometimes user sends strings such as:

"genre"=>"hip-hop\u0000hip-hop/rap" 

and rails/postgres aren't happy when trying persist on save:

an argumenterror occurred in internals#receive:   string contains null byte  activerecord (3.2.21) lib/active_record/connection_adapters/postgresql_adapter.rb:1172:in `send_query_prepared' 

how can clean string in ruby remove null bytes?

the gsub method on string suitable. can string.gsub("\u0000", '') rid of them.

http://ruby-doc.org/core-2.1.1/string.html#method-i-gsub


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -