开发者

urldecode in ruby?

开发者 https://www.devze.com 2022-12-28 07:19 出处:网络
How do I transform www.bestbuy.com/site/Electronics\\Audio\\abcat0200000.c=3fid=3开发者_如何学JAVAdabcat0200000

How do I transform

www.bestbuy.com/site/Electronics\Audio\abcat0200000.c=3fid=3开发者_如何学JAVAdabcat0200000

into its original format?

www.bestbuy.com/site/Electronics/Audio/abcat0200000.c?id=abcat0200000

Is there a urldecode?


A better method is CGI.unescape:
URI.unescape is deprecated

decoded_uri = CGI.unescape(encoded_uri)


Via decode:

require 'uri'
URI.decode(encoded_uri)

Ruby 2.7 and above:

require 'uri'
URI.decode_www_form_component(encoded_uri)


The equivalent of PHP's urldecode in Ruby is CGI::unescape.


Well the thing with =3f and =3d is quoted-printable encoding. Ruby can decode it with the .unpack("M") method.

The backslashes? They're just weird and wrong. It would probably be safe to string-replace them to / since backslash should not be in a URL to begin with.

0

精彩评论

暂无评论...
验证码 换一张
取 消