您好我正在尝试使用URI来创建一个uri,但似乎不接受括号([]):
uri = URI.parse("http://example.com")
uri.path = URI.escape("/test[1].png")
URI::InvalidComponentError: bad component(expected absolute path component): /test[1].png
from /Users/something/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/generic.rb:823:in `check_path'
Run Code Online (Sandbox Code Playgroud)
不知道该怎么办?我应该不使用URI,最后只是逃避uri?
我建议使用Addressable :: URI.
虽然Ruby的内置URI很方便,但它显示出一些年龄的迹象,我怀疑这是一个.Addressable :: URI已被提议作为URI的替代品,因为它符合当前的RFC并且功能更全面.
require 'addressable/uri'
Addressable::URI.parse("http://example.com/test[1].png")
=> #<Addressable::URI:0x81404710 URI:http://example.com/test[1].png>
Addressable::URI.parse("http://example.com/test[1].png").to_s
=> "http://example.com/test[1].png"
Run Code Online (Sandbox Code Playgroud)
对于简单,通用,使用我使用URI,只是因为.对于繁重的工作,我使用Addressable :: URI.
| 归档时间: |
|
| 查看次数: |
1048 次 |
| 最近记录: |