LoginSignup
0
0

More than 5 years have passed since last update.

Rubyでなぜかスペースがデコードできない!?

Last updated at Posted at 2018-08-03

経緯

 仕事で、URLエンコードを保存して、デコード
するという処理を作ったのですが、
 なぜかスペース(%20)のみデコードされないURLエンコードがありがはまってしまいました。
 全ての%20がデコードされないというわけではなく、特定のURLのみデコードされませんでした。
 保存時の問題なのかもしれませんが・・・
 もし同じような境遇の方がいらしたら、お力になれれば幸いです。

やった対策

以下のように強引にgsubで変換しました。

対策前
decoded_url = URI.decode( Book.first.shop_url )
"https://book/shop_url/アマゾン%20最安"

対策後
decoded_url= URI.decode(Book.first.shop_url).gsub("%20", " ")
"https://book/shop_url/アマゾン 最安"

何かありましたらコメントください。

筆者は豆腐メンタルかつ文字ベースのコミュニケーションは苦手なので、顔文字多め&優しめの言い回しでお願いします。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0