[Ruby] [Rails] I used gsub to encode the url using gsub! !! !! !!

less than 1 minute read

I used it to restrict access to posts with passwords. [Rails] How to set a password for posts, direct url countermeasures

qiita.rb


url = request.url.gsub!(/%21|%22|%23|%24|%24|%25|%26|%27|%28|%29|%2A|%2B|%2C|% 2F|%3A|%3B|%3C|%3D|%3E|%3F|%40|%5B|%5D|%5E|%60|%7B|%7C|%7D|%7E|/,
     "%21" => "!", "%22" =>'"', "%23" => "#", "%24" => "$", "%25" => "%", "%26" => "&", "%27" => "'", "%28" => "(", "%29" => ")",
     "%2A" => "*", "%2B" => "+", "%2C" => ",", "%2F" => "/", "%3A" => ":", "%3B" => ";", "%3C" => "<", "%3D" => "=", "%3E" => ">", "%3F" => "?", "%40" => "@",
     "%5B" => "[", "%5D" => "]", "%5E" => "^", "%60" => "`", "%7B" => "{", "%7C" => "|", "%7D" => "}", "%7E" => "~")

Please copy and use it.

reference https://www.seil.jp/doc/index.html#tool/url-encode.html

Tags: ,

Updated: