rubysl-uri 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/rubysl/uri.rb +2 -0
- data/lib/rubysl/uri/uri.rb +29 -0
- data/lib/rubysl/uri/version.rb +5 -0
- data/lib/uri.rb +1 -0
- data/lib/uri/common.rb +613 -0
- data/lib/uri/ftp.rb +198 -0
- data/lib/uri/generic.rb +1126 -0
- data/lib/uri/http.rb +100 -0
- data/lib/uri/https.rb +20 -0
- data/lib/uri/ldap.rb +190 -0
- data/lib/uri/ldaps.rb +12 -0
- data/lib/uri/mailto.rb +266 -0
- data/rubysl-uri.gemspec +18 -18
- data/spec/decode_www_form_component_spec.rb +7 -0
- data/spec/decode_www_form_spec.rb +7 -0
- data/spec/encode_www_form_component_spec.rb +7 -0
- data/spec/encode_www_form_spec.rb +7 -0
- data/spec/eql_spec.rb +11 -0
- data/spec/equality_spec.rb +47 -0
- data/spec/escape/decode_spec.rb +5 -0
- data/spec/escape/encode_spec.rb +5 -0
- data/spec/escape/escape_spec.rb +5 -0
- data/spec/escape/unescape_spec.rb +5 -0
- data/spec/extract_spec.rb +85 -0
- data/spec/fixtures/classes.rb +11 -0
- data/spec/fixtures/normalization.rb +54 -0
- data/spec/ftp/build_spec.rb +5 -0
- data/spec/ftp/merge_spec.rb +5 -0
- data/spec/ftp/new2_spec.rb +5 -0
- data/spec/ftp/path_spec.rb +55 -0
- data/spec/ftp/set_typecode_spec.rb +5 -0
- data/spec/ftp/to_s_spec.rb +24 -0
- data/spec/ftp/typecode_spec.rb +9 -0
- data/spec/generic/absolute_spec.rb +9 -0
- data/spec/generic/build2_spec.rb +5 -0
- data/spec/generic/build_spec.rb +5 -0
- data/spec/generic/coerce_spec.rb +5 -0
- data/spec/generic/component_ary_spec.rb +5 -0
- data/spec/generic/component_spec.rb +9 -0
- data/spec/generic/default_port_spec.rb +9 -0
- data/spec/generic/eql_spec.rb +5 -0
- data/spec/generic/equal_value_spec.rb +5 -0
- data/spec/generic/fragment_spec.rb +9 -0
- data/spec/generic/hash_spec.rb +5 -0
- data/spec/generic/hierarchical_spec.rb +5 -0
- data/spec/generic/host_spec.rb +9 -0
- data/spec/generic/inspect_spec.rb +5 -0
- data/spec/generic/merge_spec.rb +9 -0
- data/spec/generic/minus_spec.rb +5 -0
- data/spec/generic/normalize_spec.rb +9 -0
- data/spec/generic/opaque_spec.rb +9 -0
- data/spec/generic/password_spec.rb +9 -0
- data/spec/generic/path_spec.rb +9 -0
- data/spec/generic/plus_spec.rb +5 -0
- data/spec/generic/port_spec.rb +9 -0
- data/spec/generic/query_spec.rb +9 -0
- data/spec/generic/registry_spec.rb +9 -0
- data/spec/generic/relative_spec.rb +5 -0
- data/spec/generic/route_from_spec.rb +5 -0
- data/spec/generic/route_to_spec.rb +5 -0
- data/spec/generic/scheme_spec.rb +9 -0
- data/spec/generic/select_spec.rb +5 -0
- data/spec/generic/set_fragment_spec.rb +5 -0
- data/spec/generic/set_host_spec.rb +5 -0
- data/spec/generic/set_opaque_spec.rb +5 -0
- data/spec/generic/set_password_spec.rb +5 -0
- data/spec/generic/set_path_spec.rb +5 -0
- data/spec/generic/set_port_spec.rb +5 -0
- data/spec/generic/set_query_spec.rb +5 -0
- data/spec/generic/set_registry_spec.rb +5 -0
- data/spec/generic/set_scheme_spec.rb +5 -0
- data/spec/generic/set_user_spec.rb +5 -0
- data/spec/generic/set_userinfo_spec.rb +5 -0
- data/spec/generic/to_s_spec.rb +5 -0
- data/spec/generic/use_registry_spec.rb +5 -0
- data/spec/generic/user_spec.rb +9 -0
- data/spec/generic/userinfo_spec.rb +9 -0
- data/spec/http/build_spec.rb +5 -0
- data/spec/http/request_uri_spec.rb +15 -0
- data/spec/join_spec.rb +60 -0
- data/spec/ldap/attributes_spec.rb +9 -0
- data/spec/ldap/build_spec.rb +5 -0
- data/spec/ldap/dn_spec.rb +9 -0
- data/spec/ldap/extensions_spec.rb +9 -0
- data/spec/ldap/filter_spec.rb +9 -0
- data/spec/ldap/hierarchical_spec.rb +5 -0
- data/spec/ldap/scope_spec.rb +9 -0
- data/spec/ldap/set_attributes_spec.rb +5 -0
- data/spec/ldap/set_dn_spec.rb +5 -0
- data/spec/ldap/set_extensions_spec.rb +5 -0
- data/spec/ldap/set_filter_spec.rb +5 -0
- data/spec/ldap/set_scope_spec.rb +5 -0
- data/spec/mailto/build_spec.rb +98 -0
- data/spec/mailto/headers_spec.rb +9 -0
- data/spec/mailto/set_headers_spec.rb +5 -0
- data/spec/mailto/set_to_spec.rb +5 -0
- data/spec/mailto/to_mailtext_spec.rb +5 -0
- data/spec/mailto/to_rfc822text_spec.rb +5 -0
- data/spec/mailto/to_s_spec.rb +5 -0
- data/spec/mailto/to_spec.rb +9 -0
- data/spec/merge_spec.rb +21 -0
- data/spec/normalize_spec.rb +34 -0
- data/spec/parse_spec.rb +248 -0
- data/spec/parser/escape_spec.rb +7 -0
- data/spec/parser/extract_spec.rb +8 -0
- data/spec/parser/inspect_spec.rb +7 -0
- data/spec/parser/join_spec.rb +8 -0
- data/spec/parser/make_regexp_spec.rb +7 -0
- data/spec/parser/parse_spec.rb +8 -0
- data/spec/parser/split_spec.rb +7 -0
- data/spec/parser/unescape_spec.rb +7 -0
- data/spec/plus_spec.rb +488 -0
- data/spec/regexp_spec.rb +17 -0
- data/spec/route_from_spec.rb +24 -0
- data/spec/route_to_spec.rb +27 -0
- data/spec/select_spec.rb +30 -0
- data/spec/set_component_spec.rb +46 -0
- data/spec/shared/eql.rb +17 -0
- data/spec/shared/extract.rb +83 -0
- data/spec/shared/join.rb +58 -0
- data/spec/shared/parse.rb +245 -0
- data/spec/split_spec.rb +5 -0
- data/spec/uri_spec.rb +30 -0
- data/spec/util/make_components_hash_spec.rb +5 -0
- metadata +297 -88
- data/lib/rubysl-uri.rb +0 -7
- data/lib/rubysl-uri/version.rb +0 -5
data/rubysl-uri.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/uri/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-uri"
|
6
|
+
spec.version = RubySL::URI::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library uri.}
|
10
|
+
spec.summary = %q{Ruby standard library uri.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-uri"
|
12
|
+
spec.license = "BSD"
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = RubySL::Uri::VERSION
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
gem.add_development_dependency "mspec", "~> 1.5"
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
22
|
end
|
data/spec/eql_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../fixtures/normalization', __FILE__)
|
2
|
+
require File.expand_path('../shared/eql', __FILE__)
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
describe "URI#eql?" do
|
6
|
+
it_behaves_like :uri_eql, :eql?
|
7
|
+
|
8
|
+
ruby_bug "redmine:2428", "1.8.7" do
|
9
|
+
it_behaves_like :uri_eql_against_other_types, :eql?
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../fixtures/normalization', __FILE__)
|
2
|
+
require File.expand_path('../shared/eql', __FILE__)
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
describe "URI#==" do
|
6
|
+
it "ignores capitalization of host names" do
|
7
|
+
URI("http://exAMPLE.cOm").should == URI("http://example.com")
|
8
|
+
end
|
9
|
+
|
10
|
+
ruby_bug "redmine:2525", "1.8.7" do
|
11
|
+
it "ignores capitalization of scheme" do
|
12
|
+
URI("hTTp://example.com").should == URI("http://example.com")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "treats a blank path and a path of '/' as the same" do
|
17
|
+
URI("http://example.com").should == URI("http://example.com/")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "is case sensitive in all components of the URI but the host and scheme" do
|
21
|
+
URI("http://example.com/paTH").should_not == URI("http://example.com/path")
|
22
|
+
URI("http://uSer@example.com").should_not == URI("http://user@example.com")
|
23
|
+
URI("http://example.com/path?quERy").should_not == URI("http://example.com/path?query")
|
24
|
+
URI("http://example.com/#fragMENT").should_not == URI("http://example.com/#fragment")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "differentiates based on port number" do
|
28
|
+
URI("http://example.com:8080").should_not == URI("http://example.com")
|
29
|
+
end
|
30
|
+
|
31
|
+
# Note: The previous tests will be included in following ones
|
32
|
+
|
33
|
+
it_behaves_like :uri_eql, :==
|
34
|
+
|
35
|
+
it_behaves_like :uri_eql_against_other_types, :==
|
36
|
+
|
37
|
+
quarantine! do # Quarantined until redmine:2542 is accepted
|
38
|
+
it "returns true only if the normalized forms are equivalent" do
|
39
|
+
URISpec::NORMALIZED_FORMS.each do |form|
|
40
|
+
normal_uri = URI(form[:normalized])
|
41
|
+
form[:equivalent].each do |same|
|
42
|
+
URI(same).should == normal_uri
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
describe "URI.extract" do
|
4
|
+
it "behaves according to its documentation" do
|
5
|
+
URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.").should == ["http://foo.example.org/bla", "mailto:test@example.com"]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "treats contiguous URIs as a single URI" do
|
9
|
+
URI.extract('http://example.jphttp://example.jp').should == ['http://example.jphttp://example.jp']
|
10
|
+
end
|
11
|
+
|
12
|
+
it "treats pretty much anything with a colon as a URI" do
|
13
|
+
URI.extract('From: XXX [mailto:xxx@xxx.xxx.xxx]').should == ['From:', 'mailto:xxx@xxx.xxx.xxx]']
|
14
|
+
end
|
15
|
+
|
16
|
+
it "wraps a URI string in an array" do
|
17
|
+
URI.extract("http://github.com/brixen/rubyspec/tree/master").should == ["http://github.com/brixen/rubyspec/tree/master"]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "pulls a variety of protocol URIs from a string" do
|
21
|
+
URI.extract("this is a string, it has http://rubini.us/ in it").should == ["http://rubini.us/"]
|
22
|
+
URI.extract("mailto:spambait@example.com").should == ["mailto:spambait@example.com"]
|
23
|
+
URI.extract("ftp://ruby-lang.org/").should == ["ftp://ruby-lang.org/"]
|
24
|
+
URI.extract("https://mail.google.com").should == ["https://mail.google.com"]
|
25
|
+
URI.extract("anything://example.com/").should == ["anything://example.com/"]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "pulls all URIs within a string in order into an array when a block is not given" do
|
29
|
+
URI.extract("1.3. Example URI
|
30
|
+
|
31
|
+
The following examples illustrate URI that are in common use.
|
32
|
+
|
33
|
+
ftp://ftp.is.co.za/rfc/rfc1808.txt
|
34
|
+
-- ftp scheme for File Transfer Protocol services
|
35
|
+
|
36
|
+
gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles
|
37
|
+
-- gopher scheme for Gopher and Gopher+ Protocol services
|
38
|
+
|
39
|
+
http://www.math.uio.no/faq/compression-faq/part1.html
|
40
|
+
-- http scheme for Hypertext Transfer Protocol services
|
41
|
+
|
42
|
+
mailto:mduerst@ifi.unizh.ch
|
43
|
+
-- mailto scheme for electronic mail addresses
|
44
|
+
|
45
|
+
news:comp.infosystems.www.servers.unix
|
46
|
+
-- news scheme for USENET news groups and articles
|
47
|
+
|
48
|
+
telnet://melvyl.ucop.edu/
|
49
|
+
-- telnet scheme for interactive services via the TELNET Protocol
|
50
|
+
").should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:mduerst@ifi.unizh.ch","news:comp.infosystems.www.servers.unix","telnet://melvyl.ucop.edu/"]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "yields each URI in the given string in order to a block, if given, and returns nil" do
|
54
|
+
results = ["http://foo.example.org/bla", "mailto:test@example.com"]
|
55
|
+
URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.") {|uri|
|
56
|
+
uri.should == results.shift
|
57
|
+
}.should == nil
|
58
|
+
results.should == []
|
59
|
+
end
|
60
|
+
|
61
|
+
it "allows the user to specify a list of acceptable protocols of URIs to scan for" do
|
62
|
+
URI.extract("1.3. Example URI
|
63
|
+
|
64
|
+
The following examples illustrate URI that are in common use.
|
65
|
+
|
66
|
+
ftp://ftp.is.co.za/rfc/rfc1808.txt
|
67
|
+
-- ftp scheme for File Transfer Protocol services
|
68
|
+
|
69
|
+
gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles
|
70
|
+
-- gopher scheme for Gopher and Gopher+ Protocol services
|
71
|
+
|
72
|
+
http://www.math.uio.no/faq/compression-faq/part1.html
|
73
|
+
-- http scheme for Hypertext Transfer Protocol services
|
74
|
+
|
75
|
+
mailto:mduerst@ifi.unizh.ch
|
76
|
+
-- mailto scheme for electronic mail addresses
|
77
|
+
|
78
|
+
news:comp.infosystems.www.servers.unix
|
79
|
+
-- news scheme for USENET news groups and articles
|
80
|
+
|
81
|
+
telnet://melvyl.ucop.edu/
|
82
|
+
-- telnet scheme for interactive services via the TELNET Protocol
|
83
|
+
", ["http","ftp","mailto"]).should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:mduerst@ifi.unizh.ch"]
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module URISpec
|
2
|
+
# Not an exhaustive list. Refer to rfc3986
|
3
|
+
NORMALIZED_FORMS = [
|
4
|
+
{ :normalized => "http://example.com/",
|
5
|
+
:equivalent => %w{ hTTp://example.com/
|
6
|
+
http://exaMple.com/
|
7
|
+
http://exa%4dple.com/
|
8
|
+
http://exa%4Dple.com/
|
9
|
+
http://exa%6dple.com/
|
10
|
+
http://exa%6Dple.com/
|
11
|
+
http://@example.com/
|
12
|
+
http://example.com:/
|
13
|
+
http://example.com:80/
|
14
|
+
http://example.com
|
15
|
+
},
|
16
|
+
:different => %w{ http://example.com/#
|
17
|
+
http://example.com/?
|
18
|
+
http://example.com:8888/
|
19
|
+
http:///example.com
|
20
|
+
http:example.com
|
21
|
+
https://example.com/
|
22
|
+
},
|
23
|
+
},
|
24
|
+
{ :normalized => "http://example.com/index.html",
|
25
|
+
:equivalent => %w{ http://example.com/index.ht%6dl
|
26
|
+
http://example.com/index.ht%6Dl
|
27
|
+
},
|
28
|
+
:different => %w{ http://example.com/index.hTMl
|
29
|
+
http://example.com/index.ht%4dl
|
30
|
+
http://example.com/index
|
31
|
+
http://example.com/
|
32
|
+
http://example.com/
|
33
|
+
},
|
34
|
+
},
|
35
|
+
{ :normalized => "http://example.com/x?y#z",
|
36
|
+
:equivalent => %w{ http://example.com/x?y#%7a
|
37
|
+
http://example.com/x?y#%7A
|
38
|
+
http://example.com/x?%79#z
|
39
|
+
},
|
40
|
+
:different => %w{ http://example.com/x?Y#z
|
41
|
+
http://example.com/x?y#Z
|
42
|
+
http://example.com/x?y=#z
|
43
|
+
http://example.com/x?y
|
44
|
+
http://example.com/x#z
|
45
|
+
},
|
46
|
+
},
|
47
|
+
{ :normalized => "http://example.com/x?q=a%20b",
|
48
|
+
:equivalent => %w{
|
49
|
+
},
|
50
|
+
:different => %w{ http://example.com/x?q=a+b
|
51
|
+
},
|
52
|
+
},
|
53
|
+
]
|
54
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
describe "URI::FTP#path=" do
|
4
|
+
before :each do
|
5
|
+
@url = URI.parse('ftp://example.com')
|
6
|
+
end
|
7
|
+
|
8
|
+
ruby_version_is "1.8.6"..."1.8.7" do
|
9
|
+
it "does not strip the leading /" do
|
10
|
+
@url.path = '/foo'
|
11
|
+
@url.path.should == '/foo'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
ruby_version_is "1.8.7"..."1.9" do
|
16
|
+
it "requires a leading /" do
|
17
|
+
lambda { @url.path = 'foo' }.should raise_error(URI::InvalidComponentError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "strips the leading /" do
|
21
|
+
@url.path = '/foo'
|
22
|
+
@url.path.should == 'foo'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ruby_version_is "1.9" do
|
27
|
+
it "does not require a leading /" do
|
28
|
+
@url.path = 'foo'
|
29
|
+
@url.path.should == 'foo'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "does not strip the leading /" do
|
33
|
+
@url.path = '/foo'
|
34
|
+
@url.path.should == '/foo'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "URI::FTP#path" do
|
40
|
+
ruby_version_is "1.8.6"..."1.8.7" do
|
41
|
+
it "copies the path section of the URI without modification" do
|
42
|
+
url = URI.parse('ftp://example.com/%2Ffoo')
|
43
|
+
|
44
|
+
url.path.should == '/%2Ffoo'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
ruby_version_is "1.8.7" do
|
49
|
+
it "unescapes the leading /" do
|
50
|
+
url = URI.parse('ftp://example.com/%2Ffoo')
|
51
|
+
|
52
|
+
url.path.should == '/foo'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
|
4
|
+
describe "URI::FTP#to_s" do
|
5
|
+
before :each do
|
6
|
+
@url = URI.parse('ftp://example.com')
|
7
|
+
end
|
8
|
+
|
9
|
+
ruby_version_is ""..."1.9" do
|
10
|
+
it "does not escape the leading /" do
|
11
|
+
@url.path = '//foo'
|
12
|
+
|
13
|
+
@url.to_s.should == 'ftp://example.com//foo'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
ruby_version_is "1.9" do
|
18
|
+
it "escapes the leading /" do
|
19
|
+
@url.path = '/foo'
|
20
|
+
|
21
|
+
@url.to_s.should == 'ftp://example.com/%2Ffoo'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|