Tallboy
Tallboy

Reputation: 13417

How do i remove 'quotes' from strings that can contain single quotes?

I have params that is returning 4, 36, 'new tag', 52, 'Mcdonald\'s', 25 as a string.

I then split them by , and then i need to do some work on them.

First, I need to create a new tag based on that, but i need to somehow gsub (or something?) the outside quotes, but not the inner ones (if the tag contains it, like McDonald's above)

Second, I need to unescape the \ that the token input adds. I'm not sure how to do that second step so its the best security-wise

PS. I have validations on that model so I'm hoping that's good enough and i dont have to worry about some kind of SQL injection thing

Upvotes: 0

Views: 486

Answers (1)

ian
ian

Reputation: 12251

params.split(/,\s+/).map{|s| s.start_with?("'") && s.end_with?("'") ? s[1..-2] : s }

That should clear up the first part about quotes.

Upvotes: 1

Related Questions