Code Monkey home page Code Monkey logo

addressable's Introduction

Addressable

Homepage
github.com/sporkmonger/addressable
Author
Bob Aman
Copyright
Copyright © Bob Aman
License
Apache 2.0

Gem Version Build Status Test Coverage Status Documentation Coverage Status

Description

Addressable is an alternative implementation to the URI implementation that is part of Ruby's standard library. It is flexible, offers heuristic parsing, and additionally provides extensive support for IRIs and URI templates.

Addressable closely conforms to RFC 3986, RFC 3987, and RFC 6570 (level 4).

Reference

  • {Addressable::URI}
  • {Addressable::Template}

Example usage

require "addressable/uri"

uri = Addressable::URI.parse("http://example.com/path/to/resource/")
uri.scheme
#=> "http"
uri.host
#=> "example.com"
uri.path
#=> "/path/to/resource/"

uri = Addressable::URI.parse("http://www.詹姆斯.com/")
uri.normalize
#=> #<Addressable::URI:0xc9a4c8 URI:http://www.xn--8ws00zhy3a.com/>

URI Templates

For more details, see RFC 6570.

require "addressable/template"

template = Addressable::Template.new("http://example.com/{?query*}")
template.expand({
  "query" => {
    'foo' => 'bar',
    'color' => 'red'
  }
})
#=> #<Addressable::URI:0xc9d95c URI:http://example.com/?foo=bar&color=red>

template = Addressable::Template.new("http://example.com/{?one,two,three}")
template.partial_expand({"one" => "1", "three" => 3}).pattern
#=> "http://example.com/?one=1{&two}&three=3"

template = Addressable::Template.new(
  "http://{host}{/segments*}/{?one,two,bogus}{#fragment}"
)
uri = Addressable::URI.parse(
  "http://example.com/a/b/c/?one=1&two=2#foo"
)
template.extract(uri)
#=>
# {
#   "host" => "example.com",
#   "segments" => ["a", "b", "c"],
#   "one" => "1",
#   "two" => "2",
#   "fragment" => "foo"
# }

Install

$ gem install addressable

You may optionally turn on native IDN support by installing libidn and the idn gem:

$ sudo apt-get install libidn11-dev # Debian/Ubuntu
$ brew install libidn # OS X
$ gem install idn-ruby

Semantic Versioning

This project uses Semantic Versioning. You can (and should) specify your dependency using a pessimistic version constraint covering the major and minor values:

spec.add_dependency 'addressable', '~> 2.7'

If you need a specific bug fix, you can also specify minimum tiny versions without preventing updates to the latest minor release:

spec.add_dependency 'addressable', '~> 2.3', '>= 2.3.7'

addressable's People

Contributors

alejandroperea avatar amatsuda avatar andyt avatar ashmaroli avatar casperisfine avatar charleystran avatar dentarg avatar gkellogg avatar graemeboyd avatar iainbeeston avatar ianks avatar igrigorik avatar jarthod avatar jperville avatar mifrill avatar mislav avatar mothonmars avatar olleolleolle avatar petergoldstein avatar phluid61 avatar ptoomey3 avatar rkh avatar ronen avatar sanemat avatar scooter-dangle avatar sferik avatar sporkmonger avatar sqrrrl avatar tenderlove avatar therabidbanana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

addressable's Issues

Specs don't pass on jruby

Not all specs pass on jruby:

Addressable::URI when parsed from 'http://example.com/'
- should be equivalent to http://example.com
- should be equivalent to HTTP://example.com/
- should be equivalent to http://example.com:/
- should be equivalent to http://example.com:80/
- should be equivalent to http://Example.com/
- should have the correct username after assignment
- should have the correct password after assignment
- should have a request URI of '/'
- should correctly convert to a hash
- should be identical to its duplicate
- should have the same hash as its duplicate
- should have a different hash from its equivalent String value
- should have the same hash as an equal URI
- should be equivalent to http://EXAMPLE.com
- should be equivalent to http://EXAMPLE.com:80/
- should have the same hash as http://example.com/
- should have the same hash as http://example.com after assignment
- should have the same hash as http://example.com/? after assignment
- should have the same hash as http://example.com/? after assignment
- should have the same hash as http://example.com/# after assignment
- should have a different hash from http://example.com�
[java.lang.ArrayIndexOutOfBoundsException: -3
    at org.joni.ByteCodeMachine.isInBitSet(Unknown Source)
    at org.joni.ByteCodeMachine.opCClassNot(Unknown Source)
    at org.joni.ByteCodeMachine.matchAt(Unknown Source)
    at org.joni.Matcher.matchCheck(Unknown Source)
    at org.joni.Matcher.search(Unknown Source)
    at org.jruby.RubyString.gsubCommon(RubyString.java:2603)
    at org.jruby.RubyString.gsub(RubyString.java:2582)
    at org.jruby.RubyString.gsub(RubyString.java:2562)
    at org.jruby.RubyString$i_method_multi$RUBYFRAMEDINVOKER$gsub.call(org/jruby/RubyString$i_method_multi$RUBYFRAMEDINVOKER$gsub.gen)
    at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:156)
    at org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:173)
    at ruby.jit.ruby.var.tmp.portage.dev_minus_ruby.addressable_minus_2_dot_2_dot_0.work.jruby.addressable_minus_2_dot_2_dot_0.lib.addressable.uri.encode_component104665766_101901517.__file__(uri.rb:325)
    at ruby.jit.ruby.var.tmp.portage.dev_minus_ruby.addressable_minus_2_dot_2_dot_0.work.jruby.addressable_minus_2_dot_2_dot_0.lib.addressable.uri.encode_component104665766_101901517.__file__(uri.rb)

Invalid url is parsed as valid

1.9.3p125 :001 > require 'addressable/uri'
 => true 
1.9.3p125 :002 > invalid_url = "http://abc</option%3E"
 => "http://abc</option%3E" 
1.9.3p125 :004 > Addressable::URI.parse invalid_url
 => #<Addressable::URI:0x3ff79a1b09c8 URI:http://abc</option%3E> 

As this point we should have received an exception.

Standard URI goes a little further here, but still craps out:

1.9.3p125 :006 > require 'uri'
 => true 
1.9.3p125 :007 > URI.parse invalid_url
URI::InvalidURIError: bad URI(is not URI?): http://abc</option%3E
1.9.3p125 :009 > invalid_url =~ URI::regexp
 => 0 

So, here the parse method worked correctly but the regular expression still missed it.

Setting a password with the '#' character results in invalid URI

Addressable::URI.heuristic_parse("http://user:pas#[email protected]")
Addressable::URI::InvalidURIError: Invalid port number: "pas"
from /.rvm/gems/jruby-1.6.3/gems/addressable-2.2.6/lib/addressable/uri.rb:1158:in port=' from /.rvm/gems/jruby-1.6.3/gems/addressable-2.2.6/lib/addressable/uri.rb:714:ininitialize'
from org/jruby/RubyProc.java:268:in call' from org/jruby/RubyProc.java:228:incall'
from /.rvm/gems/jruby-1.6.3/gems/addressable-2.2.6/lib/addressable/uri.rb:2151:in defer_validation' from /.rvm/gems/jruby-1.6.3/gems/addressable-2.2.6/lib/addressable/uri.rb:706:ininitialize'
from /.rvm/gems/jruby-1.6.3/gems/addressable-2.2.6/lib/addressable/uri.rb:130:in parse' from /.rvm/gems/jruby-1.6.3/gems/addressable-2.2.6/lib/addressable/uri.rb:181:inheuristic_parse'
....

Looks like this regex https://github.com/sporkmonger/addressable/blob/master/lib/addressable/uri.rb#L56 doesn't take into account that user password may contain # characters

Update:

>> require 'addressable/uri'
=> true
>> uri = Addressable::URI.parse('http://example.com/')
=> #<Addressable::URI:0x80769fa0 URI:http://example.com/>
>> uri.user = 'test'
=> "test"
>> uri.password = '123#321'
=> "123#321"
>> uri
=> #<Addressable::URI:0x80769fa0 URI:http://test:123#[email protected]/>
>> uri.normalize
=> #<Addressable::URI:0x8073f3f4 URI:http://test:123%[email protected]/>

The first URI should have either automatically encoded the correct value or raise an exception. The second value would not be possible to obtain if an exception were raised.

Security issue with join

require 'addressable/uri'

puts Addressable::URI.join('http://www.example.com/', '/./')
puts Addressable::URI.join('http://www.example.com/', '/')
puts Addressable::URI.join('http://www.example.com/', '/../')
puts Addressable::URI.join('http://www.example.com/', '/.///')
puts Addressable::URI.join('http://www.example.com/', '/.///../')

will output the following

http://www.example.com/
http://www.example.com/
http://www.example.com/
http://www.example.com///
http://www.example.com///../

Inconsistent normalization of % escaping

Addressable is inconsistent in escaping uri's with %

Addressable::URI.parse("https://encrypted.google.com/search?abc=%20").normalize.to_s
=> "https://encrypted.google.com/search?abc=%20"

Addressable::URI.parse("https://encrypted.google.com/search?abc=%2B").normalize.to_s
=> "https://encrypted.google.com/search?abc=+"

There is no way to know if normalized uri will have characters escaped or not.

This issue is a result of https://github.com/myronmarston/vcr/issues/86 and bblimke/webmock#134

`sort!': comparison of Array with Array failed

Hello,

I believe I've found a bug while dealing with this monstrosity of a URL:

http://www.exitlakeside.com/-ListPrice/50/10/?re_search=1&Search%5Btownship%5D%5B%5D=%27Andover+NH%27%2C%27Belmont+NH%27%2C%27Franklin+NH%27%2C%27Gilford+NH%27%2C%27Laconia+NH%27%2C%27Northfield+NH%27%2C%27Tilton+NH%27&Search%5BiProdtypeID%5D%5B%5D=73&Search%5BiProdtypeID%5D%5B%5D=100&Search%5BiProdtypeID%5D%5B%5D=83&Search%5Bmlnumber%5D=&Search%5Bremarks%5D=&Search%5Blistprice%5D%5Bmin%5D=25000&Search%5Blistprice%5D%5Bmax%5D=150000&Search%5Btotalnumberoffullbaths%5D%5Bmin%5D=&Search%5Btotalnumberoffullbaths%5D%5Bmax%5D=&Search%5Btotalnumberofbedrooms%5D%5Bmin%5D=&Search%5Btotalnumberofbedrooms%5D%5Bmax%5D=&Search%5Bacreage%5D%5Bmin%5D=&Search%5Bacreage%5D%5Bmax%5D=&Search%5Bsquarefootage%5D%5Bmin%5D=&Search%5Bsquarefootage%5D%5Bmax%5D=&Search%5Bwaterbody%5D=&Search%5Bwater_body_type%5D=&=&=&=&=&=&=&=&submit=Search

The error occurs while trying to assign query_values:

url_string = "http://www.exitlakeside.com/-ListPrice/50/10/?re_search=1&Search%5Btownship%5D%5B%5D=%27Andover+NH%27%2C%27Belmont+NH%27%2C%27Franklin+NH%27%2C%27Gilford+NH%27%2C%27Laconia+NH%27%2C%27Northfield+NH%27%2C%27Tilton+NH%27&Search%5BiProdtypeID%5D%5B%5D=73&Search%5BiProdtypeID%5D%5B%5D=100&Search%5BiProdtypeID%5D%5B%5D=83&Search%5Bmlnumber%5D=&Search%5Bremarks%5D=&Search%5Blistprice%5D%5Bmin%5D=25000&Search%5Blistprice%5D%5Bmax%5D=150000&Search%5Btotalnumberoffullbaths%5D%5Bmin%5D=&Search%5Btotalnumberoffullbaths%5D%5Bmax%5D=&Search%5Btotalnumberofbedrooms%5D%5Bmin%5D=&Search%5Btotalnumberofbedrooms%5D%5Bmax%5D=&Search%5Bacreage%5D%5Bmin%5D=&Search%5Bacreage%5D%5Bmax%5D=&Search%5Bsquarefootage%5D%5Bmin%5D=&Search%5Bsquarefootage%5D%5Bmax%5D=&Search%5Bwaterbody%5D=&Search%5Bwater_body_type%5D=&=&=&=&=&=&=&=&submit=Search"
address = Addressable::URI.parse(url_string) 
address.query_values = address.query_values

This produces the following error:

ArgumentError: comparison of Array with Array failed
    from /Users/jspearson/.rvm/gems/ruby-1.9.3-p125/gems/addressable-2.2.7/lib/addressable/uri.rb:1511:in `sort!'
    from /Users/jspearson/.rvm/gems/ruby-1.9.3-p125/gems/addressable-2.2.7/lib/addressable/uri.rb:1511:in `query_values='
    from (irb):60
    from /Users/jspearson/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
    from /Users/jspearson/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
    from /Users/jspearson/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Odd corner case of InvalidURIError

The following code:
Addressable::URI.join "http://www.good.is/post/sponsored-post-how-corporations-are-harnessing-the-power-of-renewable-energy/", "//"

Gives:
Absolute URI missing hierarchical segment: 'http://' (Addressable::URI::InvalidURIError)

This doesn't happen with any of the following:
Addressable::URI.join "http://www.good.is/post/sponsored-post-how-corporations-are-harnessing-the-power-of-renewable-energy/", "/"
Addressable::URI.join "http://www.good.is/post/sponsored-post-how-corporations-are-harnessing-the-power-of-renewable-energy/", "/?a"
Addressable::URI.join "http://www.good.is/post/sponsored-post-how-corporations-are-harnessing-the-power-of-renewable-energy/", "///"

[Feature] Add :rack option to query_params

Every now and then, I 'm forced to use Rack::Utils.parse_query because it's the only one that gives me an "API" like result instead of something next that only Rails likes.

For example, "?select=full_name&where=type:1&where=status:2&order=last_name:desc&order=first_name

Rack:Utils.parse_query yields: {"select" => "full_name", "where" => ["type:1', "status:2"], "order" => ["last_name:desc", "first_name"]}

In #query_values, :dot yields just the second value of the same named params: {"select" => "full_name", "where" => "status:2", "order" => "first_name"}

:flat_array is closer, returning an array of arrays of values supporting maybe params with the same name, different values.

It would be nice to have a Rack::Utils compatible option which really takes the :flat_array notation and turns it into an Hash.

query_values(:notation => :rack) #=> {"select" => "full_name", "where" => ["type:1', "status:2"], "order" => ["last_name:desc", "first_name"]}

If this is something that you're interested in having, I'll gladly fork and do a pull request for it.

Ordered query_values

Under 1.8.x, it would be nice to preserve the order of the query values, such that the query string can be reconstructed without changing the signature of the URL.

Under 1.9, ruby hashes guarantee insertion order, so.. parsing the string will result in behavior above, but this breaks under 1.8. OrderedHash under 1.8? Having this as an option, or transparent would be nice.

Ex: have a use case where we need to parse the QS, delete a few variables, and re-assemble it. After re-assembling it, we need to guarantee that we'll end up with same order of parameters between different processes.

Specs fail on windows

1)
'Addressable::URI when given the root directory should convert to 'file:///c:/''
 FAILED
expected: "file:///c:/",
     got: "file:///C:/" (using ==)
./spec/addressable/uri_spec.rb:3218:

Spec failure for addressable 2.2.7 with ruby 1.8.7

I'm getting the following test failure with ruby 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]

1)
'Addressable::URI when form encoding a hash should result in correct percent encoded sequence' FAILED
expected: "%26one=%2F1&%3Dtwo=%3F2&%3Athree=%233",
     got: "%3Athree=%233&%3Dtwo=%3F2&%26one=%2F1" (using ==)
/var/tmp/portage/dev-ruby/addressable-2.2.7/work/ruby18/addressable-2.2.7/spec/addressable/uri_spec.rb:4290:
/usr/lib64/ruby/1.8/timeout.rb:53:in `timeout'

This looks like innocent fallout from the recent changes in ruby to no longer provide consistent hash ordering.

Bugs with route_to

OK so there are multiple problems with this example:

irb(main):106:0> a = Addressable::URI.parse("http://foo.com/bar")
=> #<Addressable::URI:0x80e53910 URI:http://foo.com/bar>
irb(main):107:0> b = Addressable::URI.parse("http://foo.com/bar/baz")
=> #<Addressable::URI:0x80e4fd10 URI:http://foo.com/bar/baz>
irb(main):108:0> a.route_to(b)
=> #<Addressable::URI:0x80e4a720 URI:/baz>

/baz as a relative URL from a base of http://foo.com/bar would point to http://foo.com/baz, not http://foo.com/bar/baz as asked for.

irb(main):109:0> a.join(a.route_to(b))
=> #<Addressable::URI:0x80e45b94 URI:http://foo.com/baz>

So this is wrong, and breaks the expected invariant "a.join(a.route_to(b)) == b".
Or so you'd think, except look at this:

irb(main):110:0> a.join(a.route_to(b)) == b
=> true

How does http://foo.com/baz == http://foo.com/bar/baz ?
Turns out that b.normalize has gone a bit funny

irb(main):111:0> b
=> #<Addressable::URI:0x80e4fd10 URI:http://foo.com/bar/baz>
rb(main):118:0> b.normalize
=> #<Addressable::URI:0x80e29548 URI:http://foo.com/baz>

Seems like a state-related bug; seems calling "a.route_to(b)" has an unwanted side-effect on b. If I parse b afresh, this doesn't happen.

irb(main):119:0> b = Addressable::URI.parse("http://foo.com/bar/baz")
=> #<Addressable::URI:0x80e25754 URI:http://foo.com/bar/baz>
irb(main):120:0> b.normalize
=> #<Addressable::URI:0x80e2333c URI:http://foo.com/bar/baz>

So yeah there's this state bug, and there's the fact it gave me the wrong relative URL.

Another thing is, it would be really nice if "route_to" could work with relative URLs as the start / endpoints, eg if stuff like this worked

Addressable::URI.parse("/foo/bar").route_to("/foo/baz") == Addressable::URI.parse("baz")
Addressable::URI.parse("/foo/bar/baz").route_to("/foo/boo") == Addressable::URI.parse("../boo")

but realise this raises some issues.

eg currently 'normalize' removes information from some kinds of relative URI:

irb(main):142:0> Addressable::URI.parse("../boo").normalize
=> #<Addressable::URI:0x80b0ae70 URI:boo>

after normalization this now would behave differently with 'join'

Why is Addressable so heavy on memory?

Hey,

I'm using a lib that requires addressable and I was really surprised when trying to reduce the memory footprint to see that Addressable eats about 4.8MB of memory when required!
Check these little snippets : http://gist.github.com/495292
As you can see the "uri" is roughly 0.5M, and even ActiveSupport (which is considered as heavy) is twice as light as Addressable.

I also wrote a small app that just parses URI, sleeps 10 and parses another URI (http://gist.github.com/495355) and used memprof to profile it, so it can certainly help reduce the footprint : http://www.memprof.com/dump/4c5064e17fdeb66269000001

Looks like addressable-2.1.2/lib/addressable/idna.rb is the place to look into!

Let me know if you can improve the whole thing... because 5MB is a LOT of memory these days for a single requirement =D

Trailing ? in url when setting query_values to an empty hash

describe "#query_values=" do
  context "when passed an empty Hash" do
    it "should result in the query section being removed" do
      uri = Addressable.parse("http://example.com/?login=true")
      uri.query_values = {}
      uri.to_s.should == "http://example.com/"
    end
  end
end

New Addressable::URI throws exception on #scheme=

Howdy! Thanks for the code. Found a bug I think.

    >> a = Addressable::URI.new
    => #<Addressable::URI:0x1226874 URI:>
    >> a.scheme = "http"
    Addressable::URI::InvalidURIError: Absolute URI missing hierarchical segment: 'http:'

If I set a host first, this works:

>> a.host = "foo"
=> "foo"
>> a.scheme = "http"
=> "http"

2.2.2 release cannot install on jruby

Using jruby 1.5.1 (installed with RVM):

jruby-jruby-1.5.1 ➜ gem install addressable -v=2.2.2 --no-ri --no-rdoc
ERROR:  Error installing addressable:
        invalid gem format for /Users/mmarston/.rvm/gems/jruby-1.5.1/cache/addressable-2.2.2.gem

The 2.2.1 release installed fine on jruby:

jruby-jruby-1.5.1 ➜ gem install addressable -v=2.2.1 --no-ri --no-rdoc
Successfully installed addressable-2.2.1
1 gem installed

Addressable does not work on Ruby 1.8.5

On Ruby 1.8.5 the `instance_variable_defined?' method does not exist and addressable/uri uses this method. Hence on Ruby 1.8.5 you get:

undefined method `instance_variable_defined?' for #Addressable::URI:0xb6c9cdfc

Distinction between encoded and non-encoded path separator is normalized away

The problem is that 'normalize' is un-encoding percent-encoded separator characters in the URI path. So eg

irb(main):035:0> Addressable::URI.parse("/search/foo%2Fbar") == Addressable::URI.parse("/search/foo/bar")
=> true

These are two different URLs; one has 2 path components, the other has 3. Most web app routing code would treat them differently - quite important when you're doing routes for search queries for example :)

In terms of the spec, only 'unreserved' characters can be percent-encoded or decoded without changing the semantics of the URL. If one of the reserved chars (gen-delims or sub-delims) has been encoded, you have to assume that it might have been encoded for a reason, to distinguish it from the use of that character as a separator.

So I think 'normalize' should only normalize the encoding of unreserved chars, and leave reserved ones untouched.

There were some docs saying it was designed to be user-friendly rather than strictly spec-compliant, so I guess that might be why, although even then - applications rely on encoding distinctions for separator characters in URI paths, so if the user copy/pastes a URL with these distinctions, it needs to get through to the web app untouched.

It also seems like .normalize is used under the hood in a lot of places in the codebase (eg in URI#==), so I'd prefer the default implementation of it to be spec-compliant, with a "user_friendly_normalize" as an alternative if needs be...

Every string without a period is parsed by addressable

I would like to use addressable library to validate domain names users insert, but it is failing in my simple scenario, may be I am doing something wrong here:

C:>irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'uri'
=> true
irb(main):003:0> URI.parse('mic')
=> #<URI::Generic:0x4231f50 URL:mic>

How can I validate whether this string is a valid domain name?

query values excessively decoded?

This
#!/usr/bin/env ruby

require 'bundler'
Bundler.require

require 'pp'
pp Addressable::URI.parse("http://foo.com?a=x%2By").query_values
pp CGI.parse(Addressable::URI.parse("http://foo.com?a=x%2By").query)

produces

{"a"=>"x y"}
{"a"=>["x+y"]}

I think CGI is right ... Am I missing anything?

a special normalize method?

I have an issue in em-http-request[0] that the client calls Addressable::URI#normalize! before actually doing the request, and that causes semantic changes for the URI.

Addressable::URI.parse('http://example.com/?q=%2B%26b%3Da').normalize.to_s == "http://example.com/?q=+&b=a"

Probably the client should not call Addressable::URI#normalize! before requesting the server, but according to Ilya, the author of em-http-request[1], this is a must to deal with some edge cases. I am no expert in neither URI nor HTTP, what do you think?

Thanks a lot!

[0] http://github.com/igrigorik/em-http-request

[1] http://github.com/igrigorik/em-http-request/issues/57

2.2.5 tag is a couple of commits off what rubygems has as 2.2.5

If you 'gem install addressable -v 2.2.5', what you get does not currently match exactly what is tagged on github as 2.2.5. In particular, the LICENSE has changed. The gem on rubygems.org seems to match https://github.com/sporkmonger/addressable/tree/354f223087425c5d028f19794b07682af93dd4ed, a couple of commits down from the 2.2.5 tag.

Could the tag be changed to fix this, so that it exactly matches the released gem? The license thing in particular is a hazard, as it would be possible to think you are using the gem under the MIT license (by examining the tagged version on github), but actually to have obtained it under the Apache 2 license (as in the gem). That may seem like a small thing, but it upsets the lawyers.

Error installing addressable

ERROR:  Error installing addressable:
    invalid gem format for /Users/timothyklim/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/cache/addressable-2.2.7.gem

Ruby version: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]

In 1.9.3-p0 works fine.

Net::HTTP incompatibility with 1.9.3-p0 wrt #hostname

The Net::HTTP from 1.9.3-p0 seems to call #hostname on a given URI (at least when doing Net::HTTP.post_form). The standard URI class from 1.9.3 supports this, but Addressable doesn't. For now, I'm doing a URI.parse(addressable_uri.to_s) to work around this, but it would be nice if Addressable::URI would be a full drop-in replacement again.

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol

When using addressable with ssl urls it seems to trip up the ssl http get (or head) somehow.

Steps to reproduce... run the following code commenting out the relevant uri line each time to run against normal URI parse and Addressable URI parse.

When examining both urls to_s methods they both are identical so not really sure what is going on here.

Results I get are an the above error for Addressable and http ok 200 for the URI.parse.

=== Sample Code

url = "https://payment.members.oscars.org/fmi/xsl/members/Login.xsl?redirect-url=http%3A%2F%2Fmembers.oscars.org%2F")

uri = Addressable::URI.parse(url.strip)
#uri = URI.parse(url.strip)

# retrieve data
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

http.read_timeout = 10
http.open_timeout = 10
response = http.start() {|http|
  response = http.get(uri.request_uri)
}

Segfaults on Ruby 1.9.2p0

I am keep getting segfaults that supposedly come from idna.rb:279. I am running this with RVM and get the error under bth OS X and Ubuntu.

Here is the relevant part of the stack trace:

c:0067 p:0021 s:0288 b:0287 l:000286 d:000286 METHOD /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/idna.rb:279
c:0066 p:0316 s:0283 b:0283 l:000bb4 d:000bb4 METHOD /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/idna.rb:189
c:0065 p:0051 s:0276 b:0276 l:000267 d:000275 BLOCK /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/idna.rb:124
c:0064 p:---- s:0273 b:0273 l:000272 d:000272 FINISH
c:0063 p:---- s:0271 b:0271 l:000270 d:000270 CFUNC :each
c:0062 p:0085 s:0268 b:0268 l:000267 d:000267 METHOD /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/idna.rb:119
c:0061 p:0041 s:0255 b:0255 l:000254 d:000254 METHOD /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/idna.rb:92
c:0060 p:0282 s:0250 b:0249 l:000248 d:000248 METHOD /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/uri.rb:435
c:0059 p:0072 s:0242 b:0242 l:000241 d:000241 METHOD /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/uri.rb:1345
c:0058 p:0121 s:0239 b:0231 l:000230 d:000230 METHOD /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/uri.rb:1934
c:0057 p:0086 s:0228 b:0228 l:000227 d:000227 METHOD /Users/alexander/.rvm/gems/ruby-1.9.2-p0@demandserver2/gems/addressable-2.2.2/lib/addressable/uri.rb:1982

Thank you very much

Comparing URIs broken: #normalized_query doesn't sort values

Two query strings can only be compared as strings if they are normalized and sorted.

u1 = Addressable::URI.parse '/path?foo=bar&baz=kuuq'
u2 = Addressable::URI.parse '/path?baz=kuuq&foo=bar'
u1 === u2  #=> false

The comparison here should result in true because query values order shouldn't matter.

Here's my monkeypatch: https://gist.github.com/832913

It's crude. I'd like some thoughts on this. I know that some server applications accept arrays in queries, eg.:

fruit[]=orange&fruit[]=apple

In this case, ordering is important. Maybe I should change my patch to just sort across keys and not across "key=value" pairs.

Collapses duplicate keys and only stores last value

"http://solr:8983/solr/select?q=blah&fq=index_type:lawyer&fq=displayable_b:true"

returns

{"q"=>"blah", "fq"=>"displayable_b:true"}

Losing the fq=index_type:lawyer. It probably should do something more like the following:

{"q"=>"blah", "fq"=>["index_type:lawyer", "displayable_b:true"]}

Gemspec version doesn't match Addressable::VERSION

The gemspec isn't pulling the version from Addressable::VERSION, so currently the gemspec is '2.2.5' even though Addressable::VERSION is 2.2.7. (It's causing trouble as I'm trying to resolve some crazy dependency problems.)

The README should state whether it's RFC6570 or the draft-compliant

Currently the readme states that it "It more closely conforms to the relevant RFCs", it's probably okay to omit all the specific RFCs, but since RFC6570 had been finalized just a last month, it'd be great to know if this gem fully complies to that or not quite yet.

form_encode does not handle parameters with multiple values (arrays)

Here is an example of usage:

$ Addressable::URI.form_encode({'p1' => 'v1', 'p2' => 'v2', 'p3' => ['v4', 'v5']})
=> "p3=v4v5&p2=v2&p1=v1"

This is incorrect.

The result should instead be:
=> "p3=v4&p3=v5&p2=v2&p1=v1"

What seems to be happening is that 'to_s' is getting called indiscriminately on the parameters. This is incorrect; there should be specific code for handling arrays.

Impossible to get query_values

For url like /go?x=1&x=2 query_values raises ArgumentError or return on value depending on notation.
I've solved problem using this:

url.query.split('&').map{|pair| pair.split('=').map{|c| Addressable::URI.unencode_component(c)  } }

But it would be good if Addressable will have api for handling such case.

stack level too deep (SystemStackError)

"stack level too deep (SystemStackError)"

ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]

I get this issue in addressable/idna.rb

The require of addressable/idna/pure.rb is failing.

require "addressable/idna/pure"

Running this example....
https://github.com/cjbottaro/em-xmlrpc-client

require "eventmachine"
require "em-xmlrpc-client"

EM.run do
  Fiber.new do
    client = XMLRPC::Client.new2("http://blah.com/api")
    result = client.call("someMethod", "arg1", 123) # Uses em-http-request.
  end.resume
end

The issue is being caused because the data assigned to UNICODE_DATA is too large. If I break it up with {}.merge({}).merge({}) statements I do not see this issue.

I cannot reproduce this outside of the above example.

Could URI#validate be made public?

It would be nice to be able to validate a URL using this tool before passing it to another component down my chain that uses it. validate() is currently private and I'm not sure why. Is there a strong reason for not exposing this?

Can't convert Fixnum to String

Assigning a numeric query values blows up with "Can't convert Fixnum into String" which seems counterintuitive:

uri = Addressable::URI.new
uri.query_values = { :c => 3 }
# => BANG!

Here's the offending code, I obviously need some Ruby education as I can't see why FixNum wouldn't have a to_str method.

Handling of '../..' when descending beneath root

I'm not sure if this is the expected behavior, but it seems like the following demonstrates an inconsistency in handling of '..' segments when descending beneath the root.

ruby-1.9.1-p243 > Addressable::URI.parse('http://foo.com/a/b/..').normalize
 => #<Addressable::URI:0x95ac5c URI:http://foo.com/a/> 
ruby-1.9.1-p243 > Addressable::URI.parse('http://foo.com/a/b/../..').normalize
 => #<Addressable::URI:0x957d38 URI:http://foo.com/> 
ruby-1.9.1-p243 > Addressable::URI.parse('http://foo.com/a/b/../../..').normalize
 => #<Addressable::URI:0x954b58 URI:http://foo.com/..> 

Until you hit root, '/../' and '/..' are treated synonymously. Once it descends to beneath root, the URL ends up with a path of '/..', where I would expect the path to be '/'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.