addressable-2.7.0/ 0000755 0000041 0000041 00000000000 13534474053 014031 5 ustar www-data www-data addressable-2.7.0/README.md 0000644 0000041 0000041 00000006247 13534474053 015321 0 ustar www-data www-data # Addressable
- Homepage
- github.com/sporkmonger/addressable
- Author
- Bob Aman
- Copyright
- Copyright © Bob Aman
- License
- Apache 2.0
[][gem]
[][travis]
[][coveralls]
[][inch]
[gem]: https://rubygems.org/gems/addressable
[travis]: http://travis-ci.org/sporkmonger/addressable
[coveralls]: https://coveralls.io/r/sporkmonger/addressable
[inch]: http://inch-ci.org/github/sporkmonger/addressable
# 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
```ruby
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
#=> #
```
# URI Templates
For more details, see [RFC 6570](https://www.rfc-editor.org/rfc/rfc6570.txt).
```ruby
require "addressable/template"
template = Addressable::Template.new("http://example.com/{?query*}")
template.expand({
"query" => {
'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
```console
$ gem install addressable
```
You may optionally turn on native IDN support by installing libidn and the
idn gem:
```console
$ sudo apt-get install idn # Debian/Ubuntu
$ brew install libidn # OS X
$ gem install idn-ruby
```
# Semantic Versioning
This project uses [Semantic Versioning](https://semver.org/). You can (and should) specify your
dependency using a pessimistic version constraint covering the major and minor
values:
```ruby
spec.add_dependency 'addressable', '~> 2.5'
```
If you need a specific bug fix, you can also specify minimum tiny versions
without preventing updates to the latest minor release:
```ruby
spec.add_dependency 'addressable', '~> 2.3', '>= 2.3.7'
```
addressable-2.7.0/tasks/ 0000755 0000041 0000041 00000000000 13534474053 015156 5 ustar www-data www-data addressable-2.7.0/tasks/git.rake 0000644 0000041 0000041 00000002427 13534474053 016612 0 ustar www-data www-data # frozen_string_literal: true
namespace :git do
namespace :tag do
desc "List tags from the Git repository"
task :list do
tags = `git tag -l`
tags.gsub!("\r", "")
tags = tags.split("\n").sort {|a, b| b <=> a }
puts tags.join("\n")
end
desc "Create a new tag in the Git repository"
task :create do
changelog = File.open("CHANGELOG.md", "r") { |file| file.read }
puts "-" * 80
puts changelog
puts "-" * 80
puts
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
abort "Versions don't match #{v} vs #{PKG_VERSION}" if v != PKG_VERSION
git_status = `git status`
if git_status !~ /^nothing to commit/
abort "Working directory isn't clean."
end
tag = "#{PKG_NAME}-#{PKG_VERSION}"
msg = "Release #{PKG_NAME}-#{PKG_VERSION}"
existing_tags = `git tag -l #{PKG_NAME}-*`.split('\n')
if existing_tags.include?(tag)
warn("Tag already exists, deleting...")
unless system "git tag -d #{tag}"
abort "Tag deletion failed."
end
end
puts "Creating git tag '#{tag}'..."
unless system "git tag -a -m \"#{msg}\" #{tag}"
abort "Tag creation failed."
end
end
end
end
task "gem:release" => "git:tag:create"
addressable-2.7.0/tasks/clobber.rake 0000644 0000041 0000041 00000000117 13534474053 017431 0 ustar www-data www-data # frozen_string_literal: true
desc "Remove all build products"
task "clobber"
addressable-2.7.0/tasks/metrics.rake 0000644 0000041 0000041 00000001172 13534474053 017471 0 ustar www-data www-data # frozen_string_literal: true
namespace :metrics do
task :lines do
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
for file_name in FileList["lib/**/*.rb"]
f = File.open(file_name)
while line = f.gets
lines += 1
next if line =~ /^\s*$/
next if line =~ /^\s*#/
codelines += 1
end
puts "L: #{sprintf("%4d", lines)}, " +
"LOC #{sprintf("%4d", codelines)} | #{file_name}"
total_lines += lines
total_codelines += codelines
lines, codelines = 0, 0
end
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
end
end
addressable-2.7.0/tasks/rspec.rake 0000644 0000041 0000041 00000001042 13534474053 017133 0 ustar www-data www-data # frozen_string_literal: true
require "rspec/core/rake_task"
namespace :spec do
RSpec::Core::RakeTask.new(:simplecov) do |t|
t.pattern = FileList['spec/**/*_spec.rb']
t.rspec_opts = ['--color', '--format', 'documentation']
end
namespace :simplecov do
desc "Browse the code coverage report."
task :browse => "spec:simplecov" do
require "launchy"
Launchy.open("coverage/index.html")
end
end
end
desc "Alias to spec:simplecov"
task "spec" => "spec:simplecov"
task "clobber" => ["spec:clobber_simplecov"]
addressable-2.7.0/tasks/yard.rake 0000644 0000041 0000041 00000001255 13534474053 016764 0 ustar www-data www-data # frozen_string_literal: true
require "rake"
begin
require "yard"
require "yard/rake/yardoc_task"
namespace :doc do
desc "Generate Yardoc documentation"
YARD::Rake::YardocTask.new do |yardoc|
yardoc.name = "yard"
yardoc.options = ["--verbose", "--markup", "markdown"]
yardoc.files = FileList[
"lib/**/*.rb", "ext/**/*.c",
"README.md", "CHANGELOG.md", "LICENSE.txt"
].exclude(/idna/)
end
end
task "clobber" => ["doc:clobber_yard"]
desc "Alias to doc:yard"
task "doc" => "doc:yard"
rescue LoadError
# If yard isn't available, it's not the end of the world
desc "Alias to doc:rdoc"
task "doc" => "doc:rdoc"
end
addressable-2.7.0/tasks/gem.rake 0000644 0000041 0000041 00000004555 13534474053 016603 0 ustar www-data www-data # frozen_string_literal: true
require "rubygems/package_task"
namespace :gem do
GEM_SPEC = Gem::Specification.new do |s|
s.name = PKG_NAME
s.version = PKG_VERSION
s.summary = PKG_SUMMARY
s.description = PKG_DESCRIPTION
s.files = PKG_FILES.to_a
s.has_rdoc = true
s.extra_rdoc_files = %w( README.md )
s.rdoc_options.concat ["--main", "README.md"]
if !s.respond_to?(:add_development_dependency)
puts "Cannot build Gem with this version of RubyGems."
exit(1)
end
s.required_ruby_version = ">= 2.0"
s.add_runtime_dependency "public_suffix", ">= 2.0.2", "< 5.0"
s.add_development_dependency "bundler", ">= 1.0", "< 3.0"
s.require_path = "lib"
s.author = "Bob Aman"
s.email = "bob@sporkmonger.com"
s.homepage = "https://github.com/sporkmonger/addressable"
s.license = "Apache-2.0"
end
Gem::PackageTask.new(GEM_SPEC) do |p|
p.gem_spec = GEM_SPEC
p.need_tar = true
p.need_zip = true
end
desc "Generates .gemspec file"
task :gemspec do
spec_string = GEM_SPEC.to_ruby
File.open("#{GEM_SPEC.name}.gemspec", "w") do |file|
file.write spec_string
end
end
desc "Show information about the gem"
task :debug do
puts GEM_SPEC.to_ruby
end
desc "Install the gem"
task :install => ["clobber", "gem:package"] do
sh "#{SUDO} gem install --local pkg/#{GEM_SPEC.full_name}"
end
desc "Uninstall the gem"
task :uninstall do
installed_list = Gem.source_index.find_name(PKG_NAME)
if installed_list &&
(installed_list.collect { |s| s.version.to_s}.include?(PKG_VERSION))
sh(
"#{SUDO} gem uninstall --version '#{PKG_VERSION}' " +
"--ignore-dependencies --executables #{PKG_NAME}"
)
end
end
desc "Reinstall the gem"
task :reinstall => [:uninstall, :install]
desc "Package for release"
task :release => ["gem:package", "gem:gemspec"] do |t|
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PKG_VERSION
pkg = "pkg/#{GEM_SPEC.full_name}"
changelog = File.open("CHANGELOG.md") { |file| file.read }
puts "Releasing #{PKG_NAME} v. #{PKG_VERSION}"
Rake::Task["git:tag:create"].invoke
end
end
desc "Alias to gem:package"
task "gem" => "gem:package"
task "gem:release" => "gem:gemspec"
task "clobber" => ["gem:clobber_package"]
addressable-2.7.0/spec/ 0000755 0000041 0000041 00000000000 13534474053 014763 5 ustar www-data www-data addressable-2.7.0/spec/addressable/ 0000755 0000041 0000041 00000000000 13534474053 017234 5 ustar www-data www-data addressable-2.7.0/spec/addressable/uri_spec.rb 0000644 0000041 0000041 00000554255 13534474053 021412 0 ustar www-data www-data # frozen_string_literal: true
# coding: utf-8
# Copyright (C) Bob Aman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require "spec_helper"
require "addressable/uri"
require "uri"
require "ipaddr"
if !"".respond_to?("force_encoding")
class String
def force_encoding(encoding)
@encoding = encoding
end
def encoding
@encoding ||= Encoding::ASCII_8BIT
end
end
class Encoding
def initialize(name)
@name = name
end
def to_s
return @name
end
UTF_8 = Encoding.new("UTF-8")
ASCII_8BIT = Encoding.new("US-ASCII")
end
end
module Fake
module URI
class HTTP
def initialize(uri)
@uri = uri
end
def to_s
return @uri.to_s
end
alias :to_str :to_s
end
end
end
describe Addressable::URI, "when created with a non-numeric port number" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:port => "bogus")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with a invalid encoded port number" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:port => "%eb")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with a non-string scheme" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:scheme => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a non-string user" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:user => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a non-string password" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:password => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a non-string userinfo" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:userinfo => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a non-string host" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:host => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a non-string authority" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:authority => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a non-string path" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:path => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a non-string query" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:query => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a non-string fragment" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:fragment => :bogus)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when created with a scheme but no hierarchical " +
"segment" do
it "should raise an error" do
expect(lambda do
Addressable::URI.parse("http:")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "quote handling" do
describe 'in host name' do
it "should raise an error for single quote" do
expect(lambda do
Addressable::URI.parse("http://local\"host/")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
end
describe Addressable::URI, "newline normalization" do
it "should not accept newlines in scheme" do
expect(lambda do
Addressable::URI.parse("ht%0atp://localhost/")
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should not unescape newline in path" do
uri = Addressable::URI.parse("http://localhost/%0a").normalize
expect(uri.to_s).to eq("http://localhost/%0A")
end
it "should not unescape newline in hostname" do
uri = Addressable::URI.parse("http://local%0ahost/").normalize
expect(uri.to_s).to eq("http://local%0Ahost/")
end
it "should not unescape newline in username" do
uri = Addressable::URI.parse("http://foo%0abar@localhost/").normalize
expect(uri.to_s).to eq("http://foo%0Abar@localhost/")
end
it "should not unescape newline in username" do
uri = Addressable::URI.parse("http://example:foo%0abar@example/").normalize
expect(uri.to_s).to eq("http://example:foo%0Abar@example/")
end
it "should not accept newline in hostname" do
uri = Addressable::URI.parse("http://localhost/")
expect(lambda do
uri.host = "local\nhost"
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with ambiguous path" do
it "should raise an error" do
expect(lambda do
Addressable::URI.parse("::http")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with an invalid host" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:host => "")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with a host consisting of " +
"sub-delims characters" do
it "should not raise an error" do
expect(lambda do
Addressable::URI.new(
:host => Addressable::URI::CharacterClasses::SUB_DELIMS.gsub(/\\/, '')
)
end).not_to raise_error
end
end
describe Addressable::URI, "when created with a host consisting of " +
"unreserved characters" do
it "should not raise an error" do
expect(lambda do
Addressable::URI.new(
:host => Addressable::URI::CharacterClasses::UNRESERVED.gsub(/\\/, '')
)
end).not_to raise_error
end
end
describe Addressable::URI, "when created from nil components" do
before do
@uri = Addressable::URI.new
end
it "should have a nil site value" do
expect(@uri.site).to eq(nil)
end
it "should have an empty path" do
expect(@uri.path).to eq("")
end
it "should be an empty uri" do
expect(@uri.to_s).to eq("")
end
it "should have a nil default port" do
expect(@uri.default_port).to eq(nil)
end
it "should be empty" do
expect(@uri).to be_empty
end
it "should raise an error if the scheme is set to whitespace" do
expect(lambda do
@uri.scheme = "\t \n"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if the scheme is set to all digits" do
expect(lambda do
@uri.scheme = "123"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if the scheme begins with a digit" do
expect(lambda do
@uri.scheme = "1scheme"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if the scheme begins with a plus" do
expect(lambda do
@uri.scheme = "+scheme"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if the scheme begins with a dot" do
expect(lambda do
@uri.scheme = ".scheme"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if the scheme begins with a dash" do
expect(lambda do
@uri.scheme = "-scheme"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if the scheme contains an illegal character" do
expect(lambda do
@uri.scheme = "scheme!"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if the scheme contains whitespace" do
expect(lambda do
@uri.scheme = "sch eme"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if the scheme contains a newline" do
expect(lambda do
@uri.scheme = "sch\neme"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if set into an invalid state" do
expect(lambda do
@uri.user = "user"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if set into an invalid state" do
expect(lambda do
@uri.password = "pass"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if set into an invalid state" do
expect(lambda do
@uri.scheme = "http"
@uri.fragment = "fragment"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should raise an error if set into an invalid state" do
expect(lambda do
@uri.fragment = "fragment"
@uri.scheme = "http"
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when initialized from individual components" do
before do
@uri = Addressable::URI.new(
:scheme => "http",
:user => "user",
:password => "password",
:host => "example.com",
:port => 8080,
:path => "/path",
:query => "query=value",
:fragment => "fragment"
)
end
it "returns 'http' for #scheme" do
expect(@uri.scheme).to eq("http")
end
it "returns 'http' for #normalized_scheme" do
expect(@uri.normalized_scheme).to eq("http")
end
it "returns 'user' for #user" do
expect(@uri.user).to eq("user")
end
it "returns 'user' for #normalized_user" do
expect(@uri.normalized_user).to eq("user")
end
it "returns 'password' for #password" do
expect(@uri.password).to eq("password")
end
it "returns 'password' for #normalized_password" do
expect(@uri.normalized_password).to eq("password")
end
it "returns 'user:password' for #userinfo" do
expect(@uri.userinfo).to eq("user:password")
end
it "returns 'user:password' for #normalized_userinfo" do
expect(@uri.normalized_userinfo).to eq("user:password")
end
it "returns 'example.com' for #host" do
expect(@uri.host).to eq("example.com")
end
it "returns 'example.com' for #normalized_host" do
expect(@uri.normalized_host).to eq("example.com")
end
it "returns 'com' for #tld" do
expect(@uri.tld).to eq("com")
end
it "returns 'user:password@example.com:8080' for #authority" do
expect(@uri.authority).to eq("user:password@example.com:8080")
end
it "returns 'user:password@example.com:8080' for #normalized_authority" do
expect(@uri.normalized_authority).to eq("user:password@example.com:8080")
end
it "returns 8080 for #port" do
expect(@uri.port).to eq(8080)
end
it "returns 8080 for #normalized_port" do
expect(@uri.normalized_port).to eq(8080)
end
it "returns 80 for #default_port" do
expect(@uri.default_port).to eq(80)
end
it "returns 'http://user:password@example.com:8080' for #site" do
expect(@uri.site).to eq("http://user:password@example.com:8080")
end
it "returns 'http://user:password@example.com:8080' for #normalized_site" do
expect(@uri.normalized_site).to eq("http://user:password@example.com:8080")
end
it "returns '/path' for #path" do
expect(@uri.path).to eq("/path")
end
it "returns '/path' for #normalized_path" do
expect(@uri.normalized_path).to eq("/path")
end
it "returns 'query=value' for #query" do
expect(@uri.query).to eq("query=value")
end
it "returns 'query=value' for #normalized_query" do
expect(@uri.normalized_query).to eq("query=value")
end
it "returns 'fragment' for #fragment" do
expect(@uri.fragment).to eq("fragment")
end
it "returns 'fragment' for #normalized_fragment" do
expect(@uri.normalized_fragment).to eq("fragment")
end
it "returns #hash" do
expect(@uri.hash).not_to be nil
end
it "returns #to_s" do
expect(@uri.to_s).to eq(
"http://user:password@example.com:8080/path?query=value#fragment"
)
end
it "should not be empty" do
expect(@uri).not_to be_empty
end
it "should not be frozen" do
expect(@uri).not_to be_frozen
end
it "should allow destructive operations" do
expect { @uri.normalize! }.not_to raise_error
end
end
describe Addressable::URI, "when initialized from " +
"frozen individual components" do
before do
@uri = Addressable::URI.new(
:scheme => "http".freeze,
:user => "user".freeze,
:password => "password".freeze,
:host => "example.com".freeze,
:port => "8080".freeze,
:path => "/path".freeze,
:query => "query=value".freeze,
:fragment => "fragment".freeze
)
end
it "returns 'http' for #scheme" do
expect(@uri.scheme).to eq("http")
end
it "returns 'http' for #normalized_scheme" do
expect(@uri.normalized_scheme).to eq("http")
end
it "returns 'user' for #user" do
expect(@uri.user).to eq("user")
end
it "returns 'user' for #normalized_user" do
expect(@uri.normalized_user).to eq("user")
end
it "returns 'password' for #password" do
expect(@uri.password).to eq("password")
end
it "returns 'password' for #normalized_password" do
expect(@uri.normalized_password).to eq("password")
end
it "returns 'user:password' for #userinfo" do
expect(@uri.userinfo).to eq("user:password")
end
it "returns 'user:password' for #normalized_userinfo" do
expect(@uri.normalized_userinfo).to eq("user:password")
end
it "returns 'example.com' for #host" do
expect(@uri.host).to eq("example.com")
end
it "returns 'example.com' for #normalized_host" do
expect(@uri.normalized_host).to eq("example.com")
end
it "returns 'user:password@example.com:8080' for #authority" do
expect(@uri.authority).to eq("user:password@example.com:8080")
end
it "returns 'user:password@example.com:8080' for #normalized_authority" do
expect(@uri.normalized_authority).to eq("user:password@example.com:8080")
end
it "returns 8080 for #port" do
expect(@uri.port).to eq(8080)
end
it "returns 8080 for #normalized_port" do
expect(@uri.normalized_port).to eq(8080)
end
it "returns 80 for #default_port" do
expect(@uri.default_port).to eq(80)
end
it "returns 'http://user:password@example.com:8080' for #site" do
expect(@uri.site).to eq("http://user:password@example.com:8080")
end
it "returns 'http://user:password@example.com:8080' for #normalized_site" do
expect(@uri.normalized_site).to eq("http://user:password@example.com:8080")
end
it "returns '/path' for #path" do
expect(@uri.path).to eq("/path")
end
it "returns '/path' for #normalized_path" do
expect(@uri.normalized_path).to eq("/path")
end
it "returns 'query=value' for #query" do
expect(@uri.query).to eq("query=value")
end
it "returns 'query=value' for #normalized_query" do
expect(@uri.normalized_query).to eq("query=value")
end
it "returns 'fragment' for #fragment" do
expect(@uri.fragment).to eq("fragment")
end
it "returns 'fragment' for #normalized_fragment" do
expect(@uri.normalized_fragment).to eq("fragment")
end
it "returns #hash" do
expect(@uri.hash).not_to be nil
end
it "returns #to_s" do
expect(@uri.to_s).to eq(
"http://user:password@example.com:8080/path?query=value#fragment"
)
end
it "should not be empty" do
expect(@uri).not_to be_empty
end
it "should not be frozen" do
expect(@uri).not_to be_frozen
end
it "should allow destructive operations" do
expect { @uri.normalize! }.not_to raise_error
end
end
describe Addressable::URI, "when parsed from a frozen string" do
before do
@uri = Addressable::URI.parse(
"http://user:password@example.com:8080/path?query=value#fragment".freeze
)
end
it "returns 'http' for #scheme" do
expect(@uri.scheme).to eq("http")
end
it "returns 'http' for #normalized_scheme" do
expect(@uri.normalized_scheme).to eq("http")
end
it "returns 'user' for #user" do
expect(@uri.user).to eq("user")
end
it "returns 'user' for #normalized_user" do
expect(@uri.normalized_user).to eq("user")
end
it "returns 'password' for #password" do
expect(@uri.password).to eq("password")
end
it "returns 'password' for #normalized_password" do
expect(@uri.normalized_password).to eq("password")
end
it "returns 'user:password' for #userinfo" do
expect(@uri.userinfo).to eq("user:password")
end
it "returns 'user:password' for #normalized_userinfo" do
expect(@uri.normalized_userinfo).to eq("user:password")
end
it "returns 'example.com' for #host" do
expect(@uri.host).to eq("example.com")
end
it "returns 'example.com' for #normalized_host" do
expect(@uri.normalized_host).to eq("example.com")
end
it "returns 'user:password@example.com:8080' for #authority" do
expect(@uri.authority).to eq("user:password@example.com:8080")
end
it "returns 'user:password@example.com:8080' for #normalized_authority" do
expect(@uri.normalized_authority).to eq("user:password@example.com:8080")
end
it "returns 8080 for #port" do
expect(@uri.port).to eq(8080)
end
it "returns 8080 for #normalized_port" do
expect(@uri.normalized_port).to eq(8080)
end
it "returns 80 for #default_port" do
expect(@uri.default_port).to eq(80)
end
it "returns 'http://user:password@example.com:8080' for #site" do
expect(@uri.site).to eq("http://user:password@example.com:8080")
end
it "returns 'http://user:password@example.com:8080' for #normalized_site" do
expect(@uri.normalized_site).to eq("http://user:password@example.com:8080")
end
it "returns '/path' for #path" do
expect(@uri.path).to eq("/path")
end
it "returns '/path' for #normalized_path" do
expect(@uri.normalized_path).to eq("/path")
end
it "returns 'query=value' for #query" do
expect(@uri.query).to eq("query=value")
end
it "returns 'query=value' for #normalized_query" do
expect(@uri.normalized_query).to eq("query=value")
end
it "returns 'fragment' for #fragment" do
expect(@uri.fragment).to eq("fragment")
end
it "returns 'fragment' for #normalized_fragment" do
expect(@uri.normalized_fragment).to eq("fragment")
end
it "returns #hash" do
expect(@uri.hash).not_to be nil
end
it "returns #to_s" do
expect(@uri.to_s).to eq(
"http://user:password@example.com:8080/path?query=value#fragment"
)
end
it "should not be empty" do
expect(@uri).not_to be_empty
end
it "should not be frozen" do
expect(@uri).not_to be_frozen
end
it "should allow destructive operations" do
expect { @uri.normalize! }.not_to raise_error
end
end
describe Addressable::URI, "when frozen" do
before do
@uri = Addressable::URI.new.freeze
end
it "returns nil for #scheme" do
expect(@uri.scheme).to eq(nil)
end
it "returns nil for #normalized_scheme" do
expect(@uri.normalized_scheme).to eq(nil)
end
it "returns nil for #user" do
expect(@uri.user).to eq(nil)
end
it "returns nil for #normalized_user" do
expect(@uri.normalized_user).to eq(nil)
end
it "returns nil for #password" do
expect(@uri.password).to eq(nil)
end
it "returns nil for #normalized_password" do
expect(@uri.normalized_password).to eq(nil)
end
it "returns nil for #userinfo" do
expect(@uri.userinfo).to eq(nil)
end
it "returns nil for #normalized_userinfo" do
expect(@uri.normalized_userinfo).to eq(nil)
end
it "returns nil for #host" do
expect(@uri.host).to eq(nil)
end
it "returns nil for #normalized_host" do
expect(@uri.normalized_host).to eq(nil)
end
it "returns nil for #authority" do
expect(@uri.authority).to eq(nil)
end
it "returns nil for #normalized_authority" do
expect(@uri.normalized_authority).to eq(nil)
end
it "returns nil for #port" do
expect(@uri.port).to eq(nil)
end
it "returns nil for #normalized_port" do
expect(@uri.normalized_port).to eq(nil)
end
it "returns nil for #default_port" do
expect(@uri.default_port).to eq(nil)
end
it "returns nil for #site" do
expect(@uri.site).to eq(nil)
end
it "returns nil for #normalized_site" do
expect(@uri.normalized_site).to eq(nil)
end
it "returns '' for #path" do
expect(@uri.path).to eq('')
end
it "returns '' for #normalized_path" do
expect(@uri.normalized_path).to eq('')
end
it "returns nil for #query" do
expect(@uri.query).to eq(nil)
end
it "returns nil for #normalized_query" do
expect(@uri.normalized_query).to eq(nil)
end
it "returns nil for #fragment" do
expect(@uri.fragment).to eq(nil)
end
it "returns nil for #normalized_fragment" do
expect(@uri.normalized_fragment).to eq(nil)
end
it "returns #hash" do
expect(@uri.hash).not_to be nil
end
it "returns #to_s" do
expect(@uri.to_s).to eq('')
end
it "should be empty" do
expect(@uri).to be_empty
end
it "should be frozen" do
expect(@uri).to be_frozen
end
it "should not be frozen after duping" do
expect(@uri.dup).not_to be_frozen
end
it "should not allow destructive operations" do
expect { @uri.normalize! }.to raise_error { |error|
expect(error.message).to match(/can't modify frozen/)
expect(error).to satisfy { |e| RuntimeError === e || TypeError === e }
}
end
end
describe Addressable::URI, "when frozen" do
before do
@uri = Addressable::URI.parse(
"HTTP://example.com.:%38%30/%70a%74%68?a=%31#1%323"
).freeze
end
it "returns 'HTTP' for #scheme" do
expect(@uri.scheme).to eq("HTTP")
end
it "returns 'http' for #normalized_scheme" do
expect(@uri.normalized_scheme).to eq("http")
expect(@uri.normalize.scheme).to eq("http")
end
it "returns nil for #user" do
expect(@uri.user).to eq(nil)
end
it "returns nil for #normalized_user" do
expect(@uri.normalized_user).to eq(nil)
end
it "returns nil for #password" do
expect(@uri.password).to eq(nil)
end
it "returns nil for #normalized_password" do
expect(@uri.normalized_password).to eq(nil)
end
it "returns nil for #userinfo" do
expect(@uri.userinfo).to eq(nil)
end
it "returns nil for #normalized_userinfo" do
expect(@uri.normalized_userinfo).to eq(nil)
end
it "returns 'example.com.' for #host" do
expect(@uri.host).to eq("example.com.")
end
it "returns nil for #normalized_host" do
expect(@uri.normalized_host).to eq("example.com")
expect(@uri.normalize.host).to eq("example.com")
end
it "returns 'example.com.:80' for #authority" do
expect(@uri.authority).to eq("example.com.:80")
end
it "returns 'example.com:80' for #normalized_authority" do
expect(@uri.normalized_authority).to eq("example.com")
expect(@uri.normalize.authority).to eq("example.com")
end
it "returns 80 for #port" do
expect(@uri.port).to eq(80)
end
it "returns nil for #normalized_port" do
expect(@uri.normalized_port).to eq(nil)
expect(@uri.normalize.port).to eq(nil)
end
it "returns 80 for #default_port" do
expect(@uri.default_port).to eq(80)
end
it "returns 'HTTP://example.com.:80' for #site" do
expect(@uri.site).to eq("HTTP://example.com.:80")
end
it "returns 'http://example.com' for #normalized_site" do
expect(@uri.normalized_site).to eq("http://example.com")
expect(@uri.normalize.site).to eq("http://example.com")
end
it "returns '/%70a%74%68' for #path" do
expect(@uri.path).to eq("/%70a%74%68")
end
it "returns '/path' for #normalized_path" do
expect(@uri.normalized_path).to eq("/path")
expect(@uri.normalize.path).to eq("/path")
end
it "returns 'a=%31' for #query" do
expect(@uri.query).to eq("a=%31")
end
it "returns 'a=1' for #normalized_query" do
expect(@uri.normalized_query).to eq("a=1")
expect(@uri.normalize.query).to eq("a=1")
end
it "returns '/%70a%74%68?a=%31' for #request_uri" do
expect(@uri.request_uri).to eq("/%70a%74%68?a=%31")
end
it "returns '1%323' for #fragment" do
expect(@uri.fragment).to eq("1%323")
end
it "returns '123' for #normalized_fragment" do
expect(@uri.normalized_fragment).to eq("123")
expect(@uri.normalize.fragment).to eq("123")
end
it "returns #hash" do
expect(@uri.hash).not_to be nil
end
it "returns #to_s" do
expect(@uri.to_s).to eq('HTTP://example.com.:80/%70a%74%68?a=%31#1%323')
expect(@uri.normalize.to_s).to eq('http://example.com/path?a=1#123')
end
it "should not be empty" do
expect(@uri).not_to be_empty
end
it "should be frozen" do
expect(@uri).to be_frozen
end
it "should not be frozen after duping" do
expect(@uri.dup).not_to be_frozen
end
it "should not allow destructive operations" do
expect { @uri.normalize! }.to raise_error { |error|
expect(error.message).to match(/can't modify frozen/)
expect(error).to satisfy { |e| RuntimeError === e || TypeError === e }
}
end
end
describe Addressable::URI, "when created from string components" do
before do
@uri = Addressable::URI.new(
:scheme => "http", :host => "example.com"
)
end
it "should have a site value of 'http://example.com'" do
expect(@uri.site).to eq("http://example.com")
end
it "should be equal to the equivalent parsed URI" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com"))
end
it "should raise an error if invalid components omitted" do
expect(lambda do
@uri.omit(:bogus)
end).to raise_error(ArgumentError)
expect(lambda do
@uri.omit(:scheme, :bogus, :path)
end).to raise_error(ArgumentError)
end
end
describe Addressable::URI, "when created with a nil host but " +
"non-nil authority components" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with both an authority and a user" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(
:user => "user", :authority => "user@example.com:80"
)
end).to raise_error(ArgumentError)
end
end
describe Addressable::URI, "when created with an authority and no port" do
before do
@uri = Addressable::URI.new(:authority => "user@example.com")
end
it "should not infer a port" do
expect(@uri.port).to eq(nil)
expect(@uri.default_port).to eq(nil)
expect(@uri.inferred_port).to eq(nil)
end
it "should have a site value of '//user@example.com'" do
expect(@uri.site).to eq("//user@example.com")
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when created with a host with trailing dots" do
before do
@uri = Addressable::URI.new(:authority => "example...")
end
it "should have a stable normalized form" do
expect(@uri.normalize.normalize.normalize.host).to eq(
@uri.normalize.host
)
end
end
describe Addressable::URI, "when created with a host with a backslash" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:authority => "example\\example")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with a host with a slash" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:authority => "example/example")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with a host with a space" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:authority => "example example")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when created with both a userinfo and a user" do
it "should raise an error" do
expect(lambda do
Addressable::URI.new(:user => "user", :userinfo => "user:pass")
end).to raise_error(ArgumentError)
end
end
describe Addressable::URI, "when created with a path that hasn't been " +
"prefixed with a '/' but a host specified" do
before do
@uri = Addressable::URI.new(
:scheme => "http", :host => "example.com", :path => "path"
)
end
it "should prefix a '/' to the path" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com/path"))
end
it "should have a site value of 'http://example.com'" do
expect(@uri.site).to eq("http://example.com")
end
it "should have an origin of 'http://example.com" do
expect(@uri.origin).to eq('http://example.com')
end
end
describe Addressable::URI, "when created with a path that hasn't been " +
"prefixed with a '/' but no host specified" do
before do
@uri = Addressable::URI.new(
:scheme => "http", :path => "path"
)
end
it "should not prefix a '/' to the path" do
expect(@uri).to eq(Addressable::URI.parse("http:path"))
end
it "should have a site value of 'http:'" do
expect(@uri.site).to eq("http:")
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from an Addressable::URI object" do
it "should not have unexpected side-effects" do
original_uri = Addressable::URI.parse("http://example.com/")
new_uri = Addressable::URI.parse(original_uri)
new_uri.host = 'www.example.com'
expect(new_uri.host).to eq('www.example.com')
expect(new_uri.to_s).to eq('http://www.example.com/')
expect(original_uri.host).to eq('example.com')
expect(original_uri.to_s).to eq('http://example.com/')
end
it "should not have unexpected side-effects" do
original_uri = Addressable::URI.parse("http://example.com/")
new_uri = Addressable::URI.heuristic_parse(original_uri)
new_uri.host = 'www.example.com'
expect(new_uri.host).to eq('www.example.com')
expect(new_uri.to_s).to eq('http://www.example.com/')
expect(original_uri.host).to eq('example.com')
expect(original_uri.to_s).to eq('http://example.com/')
end
it "should not have unexpected side-effects" do
original_uri = Addressable::URI.parse("http://example.com/")
new_uri = Addressable::URI.parse(original_uri)
new_uri.origin = 'https://www.example.com:8080'
expect(new_uri.host).to eq('www.example.com')
expect(new_uri.to_s).to eq('https://www.example.com:8080/')
expect(original_uri.host).to eq('example.com')
expect(original_uri.to_s).to eq('http://example.com/')
end
it "should not have unexpected side-effects" do
original_uri = Addressable::URI.parse("http://example.com/")
new_uri = Addressable::URI.heuristic_parse(original_uri)
new_uri.origin = 'https://www.example.com:8080'
expect(new_uri.host).to eq('www.example.com')
expect(new_uri.to_s).to eq('https://www.example.com:8080/')
expect(original_uri.host).to eq('example.com')
expect(original_uri.to_s).to eq('http://example.com/')
end
end
describe Addressable::URI, "when parsed from something that looks " +
"like a URI object" do
it "should parse without error" do
uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
expect(lambda do
Addressable::URI.parse(uri)
end).not_to raise_error
end
end
describe Addressable::URI, "when parsed from a standard library URI object" do
it "should parse without error" do
uri = Addressable::URI.parse(URI.parse("http://example.com/"))
expect(lambda do
Addressable::URI.parse(uri)
end).not_to raise_error
end
end
describe Addressable::URI, "when parsed from ''" do
before do
@uri = Addressable::URI.parse("")
end
it "should have no scheme" do
expect(@uri.scheme).to eq(nil)
end
it "should not be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should have a path of ''" do
expect(@uri.path).to eq("")
end
it "should have a request URI of '/'" do
expect(@uri.request_uri).to eq("/")
end
it "should be considered relative" do
expect(@uri).to be_relative
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
# Section 1.1.2 of RFC 3986
describe Addressable::URI, "when parsed from " +
"'ftp://ftp.is.co.za/rfc/rfc1808.txt'" do
before do
@uri = Addressable::URI.parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")
end
it "should use the 'ftp' scheme" do
expect(@uri.scheme).to eq("ftp")
end
it "should be considered to be ip-based" do
expect(@uri).to be_ip_based
end
it "should have a host of 'ftp.is.co.za'" do
expect(@uri.host).to eq("ftp.is.co.za")
end
it "should have inferred_port of 21" do
expect(@uri.inferred_port).to eq(21)
end
it "should have a path of '/rfc/rfc1808.txt'" do
expect(@uri.path).to eq("/rfc/rfc1808.txt")
end
it "should not have a request URI" do
expect(@uri.request_uri).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have an origin of 'ftp://ftp.is.co.za'" do
expect(@uri.origin).to eq('ftp://ftp.is.co.za')
end
end
# Section 1.1.2 of RFC 3986
describe Addressable::URI, "when parsed from " +
"'http://www.ietf.org/rfc/rfc2396.txt'" do
before do
@uri = Addressable::URI.parse("http://www.ietf.org/rfc/rfc2396.txt")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should be considered to be ip-based" do
expect(@uri).to be_ip_based
end
it "should have a host of 'www.ietf.org'" do
expect(@uri.host).to eq("www.ietf.org")
end
it "should have inferred_port of 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a path of '/rfc/rfc2396.txt'" do
expect(@uri.path).to eq("/rfc/rfc2396.txt")
end
it "should have a request URI of '/rfc/rfc2396.txt'" do
expect(@uri.request_uri).to eq("/rfc/rfc2396.txt")
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should correctly omit components" do
expect(@uri.omit(:scheme).to_s).to eq("//www.ietf.org/rfc/rfc2396.txt")
expect(@uri.omit(:path).to_s).to eq("http://www.ietf.org")
end
it "should correctly omit components destructively" do
@uri.omit!(:scheme)
expect(@uri.to_s).to eq("//www.ietf.org/rfc/rfc2396.txt")
end
it "should have an origin of 'http://www.ietf.org'" do
expect(@uri.origin).to eq('http://www.ietf.org')
end
end
# Section 1.1.2 of RFC 3986
describe Addressable::URI, "when parsed from " +
"'ldap://[2001:db8::7]/c=GB?objectClass?one'" do
before do
@uri = Addressable::URI.parse("ldap://[2001:db8::7]/c=GB?objectClass?one")
end
it "should use the 'ldap' scheme" do
expect(@uri.scheme).to eq("ldap")
end
it "should be considered to be ip-based" do
expect(@uri).to be_ip_based
end
it "should have a host of '[2001:db8::7]'" do
expect(@uri.host).to eq("[2001:db8::7]")
end
it "should have inferred_port of 389" do
expect(@uri.inferred_port).to eq(389)
end
it "should have a path of '/c=GB'" do
expect(@uri.path).to eq("/c=GB")
end
it "should not have a request URI" do
expect(@uri.request_uri).to eq(nil)
end
it "should not allow request URI assignment" do
expect(lambda do
@uri.request_uri = "/"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should have a query of 'objectClass?one'" do
expect(@uri.query).to eq("objectClass?one")
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should correctly omit components" do
expect(@uri.omit(:scheme, :authority).to_s).to eq("/c=GB?objectClass?one")
expect(@uri.omit(:path).to_s).to eq("ldap://[2001:db8::7]?objectClass?one")
end
it "should correctly omit components destructively" do
@uri.omit!(:scheme, :authority)
expect(@uri.to_s).to eq("/c=GB?objectClass?one")
end
it "should raise an error if omission would create an invalid URI" do
expect(lambda do
@uri.omit(:authority, :path)
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should have an origin of 'ldap://[2001:db8::7]'" do
expect(@uri.origin).to eq('ldap://[2001:db8::7]')
end
end
# Section 1.1.2 of RFC 3986
describe Addressable::URI, "when parsed from " +
"'mailto:John.Doe@example.com'" do
before do
@uri = Addressable::URI.parse("mailto:John.Doe@example.com")
end
it "should use the 'mailto' scheme" do
expect(@uri.scheme).to eq("mailto")
end
it "should not be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should not have an inferred_port" do
expect(@uri.inferred_port).to eq(nil)
end
it "should have a path of 'John.Doe@example.com'" do
expect(@uri.path).to eq("John.Doe@example.com")
end
it "should not have a request URI" do
expect(@uri.request_uri).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
# Section 2 of RFC 6068
describe Addressable::URI, "when parsed from " +
"'mailto:?to=addr1@an.example,addr2@an.example'" do
before do
@uri = Addressable::URI.parse(
"mailto:?to=addr1@an.example,addr2@an.example"
)
end
it "should use the 'mailto' scheme" do
expect(@uri.scheme).to eq("mailto")
end
it "should not be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should not have an inferred_port" do
expect(@uri.inferred_port).to eq(nil)
end
it "should have a path of ''" do
expect(@uri.path).to eq("")
end
it "should not have a request URI" do
expect(@uri.request_uri).to eq(nil)
end
it "should have the To: field value parameterized" do
expect(@uri.query_values(Hash)["to"]).to eq(
"addr1@an.example,addr2@an.example"
)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
# Section 1.1.2 of RFC 3986
describe Addressable::URI, "when parsed from " +
"'news:comp.infosystems.www.servers.unix'" do
before do
@uri = Addressable::URI.parse("news:comp.infosystems.www.servers.unix")
end
it "should use the 'news' scheme" do
expect(@uri.scheme).to eq("news")
end
it "should not have an inferred_port" do
expect(@uri.inferred_port).to eq(nil)
end
it "should not be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should have a path of 'comp.infosystems.www.servers.unix'" do
expect(@uri.path).to eq("comp.infosystems.www.servers.unix")
end
it "should not have a request URI" do
expect(@uri.request_uri).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
# Section 1.1.2 of RFC 3986
describe Addressable::URI, "when parsed from " +
"'tel:+1-816-555-1212'" do
before do
@uri = Addressable::URI.parse("tel:+1-816-555-1212")
end
it "should use the 'tel' scheme" do
expect(@uri.scheme).to eq("tel")
end
it "should not be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should not have an inferred_port" do
expect(@uri.inferred_port).to eq(nil)
end
it "should have a path of '+1-816-555-1212'" do
expect(@uri.path).to eq("+1-816-555-1212")
end
it "should not have a request URI" do
expect(@uri.request_uri).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
# Section 1.1.2 of RFC 3986
describe Addressable::URI, "when parsed from " +
"'telnet://192.0.2.16:80/'" do
before do
@uri = Addressable::URI.parse("telnet://192.0.2.16:80/")
end
it "should use the 'telnet' scheme" do
expect(@uri.scheme).to eq("telnet")
end
it "should have a host of '192.0.2.16'" do
expect(@uri.host).to eq("192.0.2.16")
end
it "should have a port of 80" do
expect(@uri.port).to eq(80)
end
it "should have a inferred_port of 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a default_port of 23" do
expect(@uri.default_port).to eq(23)
end
it "should be considered to be ip-based" do
expect(@uri).to be_ip_based
end
it "should have a path of '/'" do
expect(@uri.path).to eq("/")
end
it "should not have a request URI" do
expect(@uri.request_uri).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have an origin of 'telnet://192.0.2.16:80'" do
expect(@uri.origin).to eq('telnet://192.0.2.16:80')
end
end
# Section 1.1.2 of RFC 3986
describe Addressable::URI, "when parsed from " +
"'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'" do
before do
@uri = Addressable::URI.parse(
"urn:oasis:names:specification:docbook:dtd:xml:4.1.2")
end
it "should use the 'urn' scheme" do
expect(@uri.scheme).to eq("urn")
end
it "should not have an inferred_port" do
expect(@uri.inferred_port).to eq(nil)
end
it "should not be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should have a path of " +
"'oasis:names:specification:docbook:dtd:xml:4.1.2'" do
expect(@uri.path).to eq("oasis:names:specification:docbook:dtd:xml:4.1.2")
end
it "should not have a request URI" do
expect(@uri.request_uri).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when heuristically parsed from " +
"'192.0.2.16:8000/path'" do
before do
@uri = Addressable::URI.heuristic_parse("192.0.2.16:8000/path")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have a host of '192.0.2.16'" do
expect(@uri.host).to eq("192.0.2.16")
end
it "should have a port of '8000'" do
expect(@uri.port).to eq(8000)
end
it "should be considered to be ip-based" do
expect(@uri).to be_ip_based
end
it "should have a path of '/path'" do
expect(@uri.path).to eq("/path")
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have an origin of 'http://192.0.2.16:8000'" do
expect(@uri.origin).to eq('http://192.0.2.16:8000')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com'" do
before do
@uri = Addressable::URI.parse("http://example.com")
end
it "when inspected, should have the correct URI" do
expect(@uri.inspect).to include("http://example.com")
end
it "when inspected, should have the correct class name" do
expect(@uri.inspect).to include("Addressable::URI")
end
it "when inspected, should have the correct object id" do
expect(@uri.inspect).to include("%#0x" % @uri.object_id)
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should be considered to be ip-based" do
expect(@uri).to be_ip_based
end
it "should have an authority segment of 'example.com'" do
expect(@uri.authority).to eq("example.com")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should be considered ip-based" do
expect(@uri).to be_ip_based
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should not have a specified port" do
expect(@uri.port).to eq(nil)
end
it "should have an empty path" do
expect(@uri.path).to eq("")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
expect(@uri.query_values).to eq(nil)
end
it "should have a request URI of '/'" do
expect(@uri.request_uri).to eq("/")
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
it "should be considered absolute" do
expect(@uri).to be_absolute
end
it "should not be considered relative" do
expect(@uri).not_to be_relative
end
it "should not be exactly equal to 42" do
expect(@uri.eql?(42)).to eq(false)
end
it "should not be equal to 42" do
expect(@uri == 42).to eq(false)
end
it "should not be roughly equal to 42" do
expect(@uri === 42).to eq(false)
end
it "should be exactly equal to http://example.com" do
expect(@uri.eql?(Addressable::URI.parse("http://example.com"))).to eq(true)
end
it "should be roughly equal to http://example.com/" do
expect(@uri === Addressable::URI.parse("http://example.com/")).to eq(true)
end
it "should be roughly equal to the string 'http://example.com/'" do
expect(@uri === "http://example.com/").to eq(true)
end
it "should not be roughly equal to the string " +
"'http://example.com:bogus/'" do
expect(lambda do
expect(@uri === "http://example.com:bogus/").to eq(false)
end).not_to raise_error
end
it "should result in itself when joined with itself" do
expect(@uri.join(@uri).to_s).to eq("http://example.com")
expect(@uri.join!(@uri).to_s).to eq("http://example.com")
end
it "should be equivalent to http://EXAMPLE.com" do
expect(@uri).to eq(Addressable::URI.parse("http://EXAMPLE.com"))
end
it "should be equivalent to http://EXAMPLE.com:80/" do
expect(@uri).to eq(Addressable::URI.parse("http://EXAMPLE.com:80/"))
end
it "should have the same hash as http://example.com" do
expect(@uri.hash).to eq(Addressable::URI.parse("http://example.com").hash)
end
it "should have the same hash as http://EXAMPLE.com after assignment" do
@uri.origin = "http://EXAMPLE.com"
expect(@uri.hash).to eq(Addressable::URI.parse("http://EXAMPLE.com").hash)
end
it "should have a different hash from http://EXAMPLE.com" do
expect(@uri.hash).not_to eq(Addressable::URI.parse("http://EXAMPLE.com").hash)
end
it "should not allow origin assignment without scheme" do
expect(lambda do
@uri.origin = "example.com"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should not allow origin assignment without host" do
expect(lambda do
@uri.origin = "http://"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should not allow origin assignment with bogus type" do
expect(lambda do
@uri.origin = :bogus
end).to raise_error(TypeError)
end
# Section 6.2.3 of RFC 3986
it "should be equivalent to http://example.com/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com/"))
end
# Section 6.2.3 of RFC 3986
it "should be equivalent to http://example.com:/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com:/"))
end
# Section 6.2.3 of RFC 3986
it "should be equivalent to http://example.com:80/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com:80/"))
end
# Section 6.2.2.1 of RFC 3986
it "should be equivalent to http://EXAMPLE.COM/" do
expect(@uri).to eq(Addressable::URI.parse("http://EXAMPLE.COM/"))
end
it "should have a route of '/path/' to 'http://example.com/path/'" do
expect(@uri.route_to("http://example.com/path/")).to eq(
Addressable::URI.parse("/path/")
)
end
it "should have a route of '..' from 'http://example.com/path/'" do
expect(@uri.route_from("http://example.com/path/")).to eq(
Addressable::URI.parse("..")
)
end
it "should have a route of '#' to 'http://example.com/'" do
expect(@uri.route_to("http://example.com/")).to eq(
Addressable::URI.parse("#")
)
end
it "should have a route of 'http://elsewhere.com/' to " +
"'http://elsewhere.com/'" do
expect(@uri.route_to("http://elsewhere.com/")).to eq(
Addressable::URI.parse("http://elsewhere.com/")
)
end
it "when joined with 'relative/path' should be " +
"'http://example.com/relative/path'" do
expect(@uri.join('relative/path')).to eq(
Addressable::URI.parse("http://example.com/relative/path")
)
end
it "when joined with a bogus object a TypeError should be raised" do
expect(lambda do
@uri.join(42)
end).to raise_error(TypeError)
end
it "should have the correct username after assignment" do
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq(nil)
expect(@uri.to_s).to eq("http://newuser@example.com")
end
it "should have the correct username after assignment" do
@uri.user = "user@123!"
expect(@uri.user).to eq("user@123!")
expect(@uri.normalized_user).to eq("user%40123%21")
expect(@uri.password).to eq(nil)
expect(@uri.normalize.to_s).to eq("http://user%40123%21@example.com/")
end
it "should have the correct password after assignment" do
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
expect(@uri.user).to eq("")
expect(@uri.to_s).to eq("http://:newpass@example.com")
end
it "should have the correct password after assignment" do
@uri.password = "#secret@123!"
expect(@uri.password).to eq("#secret@123!")
expect(@uri.normalized_password).to eq("%23secret%40123%21")
expect(@uri.user).to eq("")
expect(@uri.normalize.to_s).to eq("http://:%23secret%40123%21@example.com/")
expect(@uri.omit(:password).to_s).to eq("http://example.com")
end
it "should have the correct user/pass after repeated assignment" do
@uri.user = nil
expect(@uri.user).to eq(nil)
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
# Username cannot be nil if the password is set
expect(@uri.user).to eq("")
expect(@uri.to_s).to eq("http://:newpass@example.com")
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
@uri.password = nil
expect(@uri.password).to eq(nil)
expect(@uri.to_s).to eq("http://newuser@example.com")
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
@uri.password = ""
expect(@uri.password).to eq("")
expect(@uri.to_s).to eq("http://newuser:@example.com")
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
@uri.user = nil
# Username cannot be nil if the password is set
expect(@uri.user).to eq("")
expect(@uri.to_s).to eq("http://:newpass@example.com")
end
it "should have the correct user/pass after userinfo assignment" do
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
@uri.userinfo = nil
expect(@uri.userinfo).to eq(nil)
expect(@uri.user).to eq(nil)
expect(@uri.password).to eq(nil)
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:user => nil,
:password => nil,
:host => "example.com",
:port => nil,
:path => "",
:query => nil,
:fragment => nil
})
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
end
# Section 5.1.2 of RFC 2616
describe Addressable::URI, "when parsed from " +
"'HTTP://www.w3.org/pub/WWW/TheProject.html'" do
before do
@uri = Addressable::URI.parse("HTTP://www.w3.org/pub/WWW/TheProject.html")
end
it "should have the correct request URI" do
expect(@uri.request_uri).to eq("/pub/WWW/TheProject.html")
end
it "should have the correct request URI after assignment" do
@uri.request_uri = "/pub/WWW/TheProject.html?"
expect(@uri.request_uri).to eq("/pub/WWW/TheProject.html?")
expect(@uri.path).to eq("/pub/WWW/TheProject.html")
expect(@uri.query).to eq("")
end
it "should have the correct request URI after assignment" do
@uri.request_uri = "/some/where/else.html"
expect(@uri.request_uri).to eq("/some/where/else.html")
expect(@uri.path).to eq("/some/where/else.html")
expect(@uri.query).to eq(nil)
end
it "should have the correct request URI after assignment" do
@uri.request_uri = "/some/where/else.html?query?string"
expect(@uri.request_uri).to eq("/some/where/else.html?query?string")
expect(@uri.path).to eq("/some/where/else.html")
expect(@uri.query).to eq("query?string")
end
it "should have the correct request URI after assignment" do
@uri.request_uri = "?x=y"
expect(@uri.request_uri).to eq("/?x=y")
expect(@uri.path).to eq("/")
expect(@uri.query).to eq("x=y")
end
it "should raise an error if the site value is set to something bogus" do
expect(lambda do
@uri.site = 42
end).to raise_error(TypeError)
end
it "should raise an error if the request URI is set to something bogus" do
expect(lambda do
@uri.request_uri = 42
end).to raise_error(TypeError)
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "HTTP",
:user => nil,
:password => nil,
:host => "www.w3.org",
:port => nil,
:path => "/pub/WWW/TheProject.html",
:query => nil,
:fragment => nil
})
end
it "should have an origin of 'http://www.w3.org'" do
expect(@uri.origin).to eq('http://www.w3.org')
end
end
describe Addressable::URI, "when parsing IPv6 addresses" do
it "should not raise an error for " +
"'http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
Addressable::URI.parse("http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/")
end
it "should not raise an error for " +
"'http://[fe80:0:0:0:200:f8ff:fe21:67cf]/'" do
Addressable::URI.parse("http://[fe80:0:0:0:200:f8ff:fe21:67cf]/")
end
it "should not raise an error for " +
"'http://[fe80::200:f8ff:fe21:67cf]/'" do
Addressable::URI.parse("http://[fe80::200:f8ff:fe21:67cf]/")
end
it "should not raise an error for " +
"'http://[::1]/'" do
Addressable::URI.parse("http://[::1]/")
end
it "should not raise an error for " +
"'http://[fe80::1]/'" do
Addressable::URI.parse("http://[fe80::1]/")
end
it "should raise an error for " +
"'http://[]/'" do
expect(lambda do
Addressable::URI.parse("http://[]/")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when parsing IPv6 address" do
subject { Addressable::URI.parse("http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/") }
its(:host) { should == '[3ffe:1900:4545:3:200:f8ff:fe21:67cf]' }
its(:hostname) { should == '3ffe:1900:4545:3:200:f8ff:fe21:67cf' }
end
describe Addressable::URI, "when assigning IPv6 address" do
it "should allow to set bare IPv6 address as hostname" do
uri = Addressable::URI.parse("http://[::1]/")
uri.hostname = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
expect(uri.to_s).to eq('http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/')
end
it "should allow to set bare IPv6 address as hostname with IPAddr object" do
uri = Addressable::URI.parse("http://[::1]/")
uri.hostname = IPAddr.new('3ffe:1900:4545:3:200:f8ff:fe21:67cf')
expect(uri.to_s).to eq('http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/')
end
it "should not allow to set bare IPv6 address as host" do
uri = Addressable::URI.parse("http://[::1]/")
skip "not checked"
expect(lambda do
uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when parsing IPvFuture addresses" do
it "should not raise an error for " +
"'http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
Addressable::URI.parse("http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/")
end
it "should not raise an error for " +
"'http://[vff.fe80:0:0:0:200:f8ff:fe21:67cf]/'" do
Addressable::URI.parse("http://[vff.fe80:0:0:0:200:f8ff:fe21:67cf]/")
end
it "should not raise an error for " +
"'http://[v12.fe80::200:f8ff:fe21:67cf]/'" do
Addressable::URI.parse("http://[v12.fe80::200:f8ff:fe21:67cf]/")
end
it "should not raise an error for " +
"'http://[va0.::1]/'" do
Addressable::URI.parse("http://[va0.::1]/")
end
it "should not raise an error for " +
"'http://[v255.fe80::1]/'" do
Addressable::URI.parse("http://[v255.fe80::1]/")
end
it "should raise an error for " +
"'http://[v0.]/'" do
expect(lambda do
Addressable::URI.parse("http://[v0.]/")
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/'" do
before do
@uri = Addressable::URI.parse("http://example.com/")
end
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
it "should be equivalent to http://example.com" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com"))
end
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
it "should be equivalent to HTTP://example.com/" do
expect(@uri).to eq(Addressable::URI.parse("HTTP://example.com/"))
end
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
it "should be equivalent to http://example.com:/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com:/"))
end
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
it "should be equivalent to http://example.com:80/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com:80/"))
end
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
it "should be equivalent to http://Example.com/" do
expect(@uri).to eq(Addressable::URI.parse("http://Example.com/"))
end
it "should have the correct username after assignment" do
@uri.user = nil
expect(@uri.user).to eq(nil)
expect(@uri.password).to eq(nil)
expect(@uri.to_s).to eq("http://example.com/")
end
it "should have the correct password after assignment" do
@uri.password = nil
expect(@uri.password).to eq(nil)
expect(@uri.user).to eq(nil)
expect(@uri.to_s).to eq("http://example.com/")
end
it "should have a request URI of '/'" do
expect(@uri.request_uri).to eq("/")
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:user => nil,
:password => nil,
:host => "example.com",
:port => nil,
:path => "/",
:query => nil,
:fragment => nil
})
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have the same hash as its duplicate" do
expect(@uri.hash).to eq(@uri.dup.hash)
end
it "should have a different hash from its equivalent String value" do
expect(@uri.hash).not_to eq(@uri.to_s.hash)
end
it "should have the same hash as an equal URI" do
expect(@uri.hash).to eq(Addressable::URI.parse("http://example.com/").hash)
end
it "should be equivalent to http://EXAMPLE.com" do
expect(@uri).to eq(Addressable::URI.parse("http://EXAMPLE.com"))
end
it "should be equivalent to http://EXAMPLE.com:80/" do
expect(@uri).to eq(Addressable::URI.parse("http://EXAMPLE.com:80/"))
end
it "should have the same hash as http://example.com/" do
expect(@uri.hash).to eq(Addressable::URI.parse("http://example.com/").hash)
end
it "should have the same hash as http://example.com after assignment" do
@uri.path = ""
expect(@uri.hash).to eq(Addressable::URI.parse("http://example.com").hash)
end
it "should have the same hash as http://example.com/? after assignment" do
@uri.query = ""
expect(@uri.hash).to eq(Addressable::URI.parse("http://example.com/?").hash)
end
it "should have the same hash as http://example.com/? after assignment" do
@uri.query_values = {}
expect(@uri.hash).to eq(Addressable::URI.parse("http://example.com/?").hash)
end
it "should have the same hash as http://example.com/# after assignment" do
@uri.fragment = ""
expect(@uri.hash).to eq(Addressable::URI.parse("http://example.com/#").hash)
end
it "should have a different hash from http://example.com" do
expect(@uri.hash).not_to eq(Addressable::URI.parse("http://example.com").hash)
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com?#'" do
before do
@uri = Addressable::URI.parse("http://example.com?#")
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:user => nil,
:password => nil,
:host => "example.com",
:port => nil,
:path => "",
:query => "",
:fragment => ""
})
end
it "should have a request URI of '/?'" do
expect(@uri.request_uri).to eq("/?")
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq("http://example.com")
end
end
describe Addressable::URI, "when parsed from " +
"'http://@example.com/'" do
before do
@uri = Addressable::URI.parse("http://@example.com/")
end
it "should be equivalent to http://example.com" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com"))
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:user => "",
:password => nil,
:host => "example.com",
:port => nil,
:path => "/",
:query => nil,
:fragment => nil
})
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com./'" do
before do
@uri = Addressable::URI.parse("http://example.com./")
end
it "should be equivalent to http://example.com" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com"))
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://:@example.com/'" do
before do
@uri = Addressable::URI.parse("http://:@example.com/")
end
it "should be equivalent to http://example.com" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com"))
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:user => "",
:password => "",
:host => "example.com",
:port => nil,
:path => "/",
:query => nil,
:fragment => nil
})
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
end
describe Addressable::URI, "when parsed from " +
"'HTTP://EXAMPLE.COM/'" do
before do
@uri = Addressable::URI.parse("HTTP://EXAMPLE.COM/")
end
it "should be equivalent to http://example.com" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com"))
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "HTTP",
:user => nil,
:password => nil,
:host => "EXAMPLE.COM",
:port => nil,
:path => "/",
:query => nil,
:fragment => nil
})
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
it "should have a tld of 'com'" do
expect(@uri.tld).to eq('com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://www.example.co.uk/'" do
before do
@uri = Addressable::URI.parse("http://www.example.co.uk/")
end
it "should have an origin of 'http://www.example.co.uk'" do
expect(@uri.origin).to eq('http://www.example.co.uk')
end
it "should have a tld of 'co.uk'" do
expect(@uri.tld).to eq('co.uk')
end
it "should have a domain of 'example.co.uk'" do
expect(@uri.domain).to eq('example.co.uk')
end
end
describe Addressable::URI, "when parsed from " +
"'http://sub_domain.blogspot.com/'" do
before do
@uri = Addressable::URI.parse("http://sub_domain.blogspot.com/")
end
it "should have an origin of 'http://sub_domain.blogspot.com'" do
expect(@uri.origin).to eq('http://sub_domain.blogspot.com')
end
it "should have a tld of 'com'" do
expect(@uri.tld).to eq('com')
end
it "should have a domain of 'blogspot.com'" do
expect(@uri.domain).to eq('blogspot.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/~smith/'" do
before do
@uri = Addressable::URI.parse("http://example.com/~smith/")
end
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
it "should be equivalent to http://example.com/%7Esmith/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com/%7Esmith/"))
end
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
it "should be equivalent to http://example.com/%7esmith/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com/%7esmith/"))
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/%E8'" do
before do
@uri = Addressable::URI.parse("http://example.com/%E8")
end
it "should not raise an exception when normalized" do
expect(lambda do
@uri.normalize
end).not_to raise_error
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should not change if encoded with the normalizing algorithm" do
expect(Addressable::URI.normalized_encode(@uri).to_s).to eq(
"http://example.com/%E8"
)
expect(Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s).to be ===
"http://example.com/%E8"
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/path%2Fsegment/'" do
before do
@uri = Addressable::URI.parse("http://example.com/path%2Fsegment/")
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should be equal to 'http://example.com/path%2Fsegment/'" do
expect(@uri.normalize).to be_eql(
Addressable::URI.parse("http://example.com/path%2Fsegment/")
)
end
it "should not be equal to 'http://example.com/path/segment/'" do
expect(@uri).not_to eq(
Addressable::URI.parse("http://example.com/path/segment/")
)
end
it "should not be equal to 'http://example.com/path/segment/'" do
expect(@uri.normalize).not_to be_eql(
Addressable::URI.parse("http://example.com/path/segment/")
)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?%F6'" do
before do
@uri = Addressable::URI.parse("http://example.com/?%F6")
end
it "should not raise an exception when normalized" do
expect(lambda do
@uri.normalize
end).not_to raise_error
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should not change if encoded with the normalizing algorithm" do
expect(Addressable::URI.normalized_encode(@uri).to_s).to eq(
"http://example.com/?%F6"
)
expect(Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s).to be ===
"http://example.com/?%F6"
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/#%F6'" do
before do
@uri = Addressable::URI.parse("http://example.com/#%F6")
end
it "should not raise an exception when normalized" do
expect(lambda do
@uri.normalize
end).not_to raise_error
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should not change if encoded with the normalizing algorithm" do
expect(Addressable::URI.normalized_encode(@uri).to_s).to eq(
"http://example.com/#%F6"
)
expect(Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s).to be ===
"http://example.com/#%F6"
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/%C3%87'" do
before do
@uri = Addressable::URI.parse("http://example.com/%C3%87")
end
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
it "should be equivalent to 'http://example.com/C%CC%A7'" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com/C%CC%A7"))
end
it "should not change if encoded with the normalizing algorithm" do
expect(Addressable::URI.normalized_encode(@uri).to_s).to eq(
"http://example.com/%C3%87"
)
expect(Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s).to be ===
"http://example.com/%C3%87"
end
it "should raise an error if encoding with an unexpected return type" do
expect(lambda do
Addressable::URI.normalized_encode(@uri, Integer)
end).to raise_error(TypeError)
end
it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
expect(Addressable::URI.encode(@uri).to_s).to eq(
"http://example.com/%25C3%2587"
)
end
it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
expect(Addressable::URI.encode(@uri, Addressable::URI)).to eq(
Addressable::URI.parse("http://example.com/%25C3%2587")
)
end
it "should raise an error if encoding with an unexpected return type" do
expect(lambda do
Addressable::URI.encode(@uri, Integer)
end).to raise_error(TypeError)
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?q=string'" do
before do
@uri = Addressable::URI.parse("http://example.com/?q=string")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have an authority segment of 'example.com'" do
expect(@uri.authority).to eq("example.com")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a path of '/'" do
expect(@uri.path).to eq("/")
end
it "should have a query string of 'q=string'" do
expect(@uri.query).to eq("q=string")
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
it "should be considered absolute" do
expect(@uri).to be_absolute
end
it "should not be considered relative" do
expect(@uri).not_to be_relative
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com:80/'" do
before do
@uri = Addressable::URI.parse("http://example.com:80/")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have an authority segment of 'example.com:80'" do
expect(@uri.authority).to eq("example.com:80")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have explicit port 80" do
expect(@uri.port).to eq(80)
end
it "should have a path of '/'" do
expect(@uri.path).to eq("/")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
it "should be considered absolute" do
expect(@uri).to be_absolute
end
it "should not be considered relative" do
expect(@uri).not_to be_relative
end
it "should be exactly equal to http://example.com:80/" do
expect(@uri.eql?(Addressable::URI.parse("http://example.com:80/"))).to eq(true)
end
it "should be roughly equal to http://example.com/" do
expect(@uri === Addressable::URI.parse("http://example.com/")).to eq(true)
end
it "should be roughly equal to the string 'http://example.com/'" do
expect(@uri === "http://example.com/").to eq(true)
end
it "should not be roughly equal to the string " +
"'http://example.com:bogus/'" do
expect(lambda do
expect(@uri === "http://example.com:bogus/").to eq(false)
end).not_to raise_error
end
it "should result in itself when joined with itself" do
expect(@uri.join(@uri).to_s).to eq("http://example.com:80/")
expect(@uri.join!(@uri).to_s).to eq("http://example.com:80/")
end
# Section 6.2.3 of RFC 3986
it "should be equal to http://example.com/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com/"))
end
# Section 6.2.3 of RFC 3986
it "should be equal to http://example.com:/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com:/"))
end
# Section 6.2.3 of RFC 3986
it "should be equal to http://example.com:80/" do
expect(@uri).to eq(Addressable::URI.parse("http://example.com:80/"))
end
# Section 6.2.2.1 of RFC 3986
it "should be equal to http://EXAMPLE.COM/" do
expect(@uri).to eq(Addressable::URI.parse("http://EXAMPLE.COM/"))
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:user => nil,
:password => nil,
:host => "example.com",
:port => 80,
:path => "/",
:query => nil,
:fragment => nil
})
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
it "should not change if encoded with the normalizing algorithm" do
expect(Addressable::URI.normalized_encode(@uri).to_s).to eq(
"http://example.com:80/"
)
expect(Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s).to be ===
"http://example.com:80/"
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com:8080/'" do
before do
@uri = Addressable::URI.parse("http://example.com:8080/")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have an authority segment of 'example.com:8080'" do
expect(@uri.authority).to eq("example.com:8080")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should use port 8080" do
expect(@uri.inferred_port).to eq(8080)
end
it "should have explicit port 8080" do
expect(@uri.port).to eq(8080)
end
it "should have default port 80" do
expect(@uri.default_port).to eq(80)
end
it "should have a path of '/'" do
expect(@uri.path).to eq("/")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
it "should be considered absolute" do
expect(@uri).to be_absolute
end
it "should not be considered relative" do
expect(@uri).not_to be_relative
end
it "should be exactly equal to http://example.com:8080/" do
expect(@uri.eql?(Addressable::URI.parse(
"http://example.com:8080/"))).to eq(true)
end
it "should have a route of 'http://example.com:8080/' from " +
"'http://example.com/path/to/'" do
expect(@uri.route_from("http://example.com/path/to/")).to eq(
Addressable::URI.parse("http://example.com:8080/")
)
end
it "should have a route of 'http://example.com:8080/' from " +
"'http://example.com:80/path/to/'" do
expect(@uri.route_from("http://example.com:80/path/to/")).to eq(
Addressable::URI.parse("http://example.com:8080/")
)
end
it "should have a route of '../../' from " +
"'http://example.com:8080/path/to/'" do
expect(@uri.route_from("http://example.com:8080/path/to/")).to eq(
Addressable::URI.parse("../../")
)
end
it "should have a route of 'http://example.com:8080/' from " +
"'http://user:pass@example.com/path/to/'" do
expect(@uri.route_from("http://user:pass@example.com/path/to/")).to eq(
Addressable::URI.parse("http://example.com:8080/")
)
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:user => nil,
:password => nil,
:host => "example.com",
:port => 8080,
:path => "/",
:query => nil,
:fragment => nil
})
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have an origin of 'http://example.com:8080'" do
expect(@uri.origin).to eq('http://example.com:8080')
end
it "should not change if encoded with the normalizing algorithm" do
expect(Addressable::URI.normalized_encode(@uri).to_s).to eq(
"http://example.com:8080/"
)
expect(Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s).to be ===
"http://example.com:8080/"
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com:%38%30/'" do
before do
@uri = Addressable::URI.parse("http://example.com:%38%30/")
end
it "should have the correct port" do
expect(@uri.port).to eq(80)
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/%2E/'" do
before do
@uri = Addressable::URI.parse("http://example.com/%2E/")
end
it "should be considered to be in normal form" do
skip(
'path segment normalization should happen before ' +
'percent escaping normalization'
)
@uri.normalize.should be_eql(@uri)
end
it "should normalize to 'http://example.com/%2E/'" do
skip(
'path segment normalization should happen before ' +
'percent escaping normalization'
)
expect(@uri.normalize).to eq("http://example.com/%2E/")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/..'" do
before do
@uri = Addressable::URI.parse("http://example.com/..")
end
it "should have the correct port" do
expect(@uri.inferred_port).to eq(80)
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/../..'" do
before do
@uri = Addressable::URI.parse("http://example.com/../..")
end
it "should have the correct port" do
expect(@uri.inferred_port).to eq(80)
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/path(/..'" do
before do
@uri = Addressable::URI.parse("http://example.com/path(/..")
end
it "should have the correct port" do
expect(@uri.inferred_port).to eq(80)
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/(path)/..'" do
before do
@uri = Addressable::URI.parse("http://example.com/(path)/..")
end
it "should have the correct port" do
expect(@uri.inferred_port).to eq(80)
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/path(/../'" do
before do
@uri = Addressable::URI.parse("http://example.com/path(/../")
end
it "should have the correct port" do
expect(@uri.inferred_port).to eq(80)
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/(path)/../'" do
before do
@uri = Addressable::URI.parse("http://example.com/(path)/../")
end
it "should have the correct port" do
expect(@uri.inferred_port).to eq(80)
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
end
end
describe Addressable::URI, "when parsed from " +
"'/..//example.com'" do
before do
@uri = Addressable::URI.parse("/..//example.com")
end
it "should become invalid when normalized" do
expect(lambda do
@uri.normalize
end).to raise_error(Addressable::URI::InvalidURIError, /authority/)
end
it "should have a path of '/..//example.com'" do
expect(@uri.path).to eq("/..//example.com")
end
end
describe Addressable::URI, "when parsed from '/a/b/c/./../../g'" do
before do
@uri = Addressable::URI.parse("/a/b/c/./../../g")
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
# Section 5.2.4 of RFC 3986
it "should normalize to '/a/g'" do
expect(@uri.normalize.to_s).to eq("/a/g")
end
end
describe Addressable::URI, "when parsed from 'mid/content=5/../6'" do
before do
@uri = Addressable::URI.parse("mid/content=5/../6")
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
# Section 5.2.4 of RFC 3986
it "should normalize to 'mid/6'" do
expect(@uri.normalize.to_s).to eq("mid/6")
end
end
describe Addressable::URI, "when parsed from " +
"'http://www.example.com///../'" do
before do
@uri = Addressable::URI.parse('http://www.example.com///../')
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
it "should normalize to 'http://www.example.com//'" do
expect(@uri.normalize.to_s).to eq("http://www.example.com//")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/path/to/resource/'" do
before do
@uri = Addressable::URI.parse("http://example.com/path/to/resource/")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have an authority segment of 'example.com'" do
expect(@uri.authority).to eq("example.com")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a path of '/path/to/resource/'" do
expect(@uri.path).to eq("/path/to/resource/")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
it "should be considered absolute" do
expect(@uri).to be_absolute
end
it "should not be considered relative" do
expect(@uri).not_to be_relative
end
it "should be exactly equal to http://example.com:8080/" do
expect(@uri.eql?(Addressable::URI.parse(
"http://example.com/path/to/resource/"))).to eq(true)
end
it "should have a route of 'resource/' from " +
"'http://example.com/path/to/'" do
expect(@uri.route_from("http://example.com/path/to/")).to eq(
Addressable::URI.parse("resource/")
)
end
it "should have a route of '../' from " +
"'http://example.com/path/to/resource/sub'" do
expect(@uri.route_from("http://example.com/path/to/resource/sub")).to eq(
Addressable::URI.parse("../")
)
end
it "should have a route of 'resource/' from " +
"'http://example.com/path/to/another'" do
expect(@uri.route_from("http://example.com/path/to/another")).to eq(
Addressable::URI.parse("resource/")
)
end
it "should have a route of 'resource/' from " +
"'http://example.com/path/to/res'" do
expect(@uri.route_from("http://example.com/path/to/res")).to eq(
Addressable::URI.parse("resource/")
)
end
it "should have a route of 'resource/' from " +
"'http://example.com:80/path/to/'" do
expect(@uri.route_from("http://example.com:80/path/to/")).to eq(
Addressable::URI.parse("resource/")
)
end
it "should have a route of 'http://example.com/path/to/' from " +
"'http://example.com:8080/path/to/'" do
expect(@uri.route_from("http://example.com:8080/path/to/")).to eq(
Addressable::URI.parse("http://example.com/path/to/resource/")
)
end
it "should have a route of 'http://example.com/path/to/' from " +
"'http://user:pass@example.com/path/to/'" do
expect(@uri.route_from("http://user:pass@example.com/path/to/")).to eq(
Addressable::URI.parse("http://example.com/path/to/resource/")
)
end
it "should have a route of '../../path/to/resource/' from " +
"'http://example.com/to/resource/'" do
expect(@uri.route_from("http://example.com/to/resource/")).to eq(
Addressable::URI.parse("../../path/to/resource/")
)
end
it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:user => nil,
:password => nil,
:host => "example.com",
:port => nil,
:path => "/path/to/resource/",
:query => nil,
:fragment => nil
})
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
end
describe Addressable::URI, "when parsed from " +
"'relative/path/to/resource'" do
before do
@uri = Addressable::URI.parse("relative/path/to/resource")
end
it "should not have a scheme" do
expect(@uri.scheme).to eq(nil)
end
it "should not be considered ip-based" do
expect(@uri).not_to be_ip_based
end
it "should not have an authority segment" do
expect(@uri.authority).to eq(nil)
end
it "should not have a host" do
expect(@uri.host).to eq(nil)
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should not have a port" do
expect(@uri.port).to eq(nil)
end
it "should have a path of 'relative/path/to/resource'" do
expect(@uri.path).to eq("relative/path/to/resource")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
it "should not be considered absolute" do
expect(@uri).not_to be_absolute
end
it "should be considered relative" do
expect(@uri).to be_relative
end
it "should raise an error if routing is attempted" do
expect(lambda do
@uri.route_to("http://example.com/")
end).to raise_error(ArgumentError, /relative\/path\/to\/resource/)
expect(lambda do
@uri.route_from("http://example.com/")
end).to raise_error(ArgumentError, /relative\/path\/to\/resource/)
end
it "when joined with 'another/relative/path' should be " +
"'relative/path/to/another/relative/path'" do
expect(@uri.join('another/relative/path')).to eq(
Addressable::URI.parse("relative/path/to/another/relative/path")
)
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
end
describe Addressable::URI, "when parsed from " +
"'relative_path_with_no_slashes'" do
before do
@uri = Addressable::URI.parse("relative_path_with_no_slashes")
end
it "should not have a scheme" do
expect(@uri.scheme).to eq(nil)
end
it "should not be considered ip-based" do
expect(@uri).not_to be_ip_based
end
it "should not have an authority segment" do
expect(@uri.authority).to eq(nil)
end
it "should not have a host" do
expect(@uri.host).to eq(nil)
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should not have a port" do
expect(@uri.port).to eq(nil)
end
it "should have a path of 'relative_path_with_no_slashes'" do
expect(@uri.path).to eq("relative_path_with_no_slashes")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
it "should not be considered absolute" do
expect(@uri).not_to be_absolute
end
it "should be considered relative" do
expect(@uri).to be_relative
end
it "when joined with 'another_relative_path' should be " +
"'another_relative_path'" do
expect(@uri.join('another_relative_path')).to eq(
Addressable::URI.parse("another_relative_path")
)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/file.txt'" do
before do
@uri = Addressable::URI.parse("http://example.com/file.txt")
end
it "should have a scheme of 'http'" do
expect(@uri.scheme).to eq("http")
end
it "should have an authority segment of 'example.com'" do
expect(@uri.authority).to eq("example.com")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a path of '/file.txt'" do
expect(@uri.path).to eq("/file.txt")
end
it "should have a basename of 'file.txt'" do
expect(@uri.basename).to eq("file.txt")
end
it "should have an extname of '.txt'" do
expect(@uri.extname).to eq(".txt")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/file.txt;parameter'" do
before do
@uri = Addressable::URI.parse("http://example.com/file.txt;parameter")
end
it "should have a scheme of 'http'" do
expect(@uri.scheme).to eq("http")
end
it "should have an authority segment of 'example.com'" do
expect(@uri.authority).to eq("example.com")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a path of '/file.txt;parameter'" do
expect(@uri.path).to eq("/file.txt;parameter")
end
it "should have a basename of 'file.txt'" do
expect(@uri.basename).to eq("file.txt")
end
it "should have an extname of '.txt'" do
expect(@uri.extname).to eq(".txt")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/file.txt;x=y'" do
before do
@uri = Addressable::URI.parse("http://example.com/file.txt;x=y")
end
it "should have a scheme of 'http'" do
expect(@uri.scheme).to eq("http")
end
it "should have a scheme of 'http'" do
expect(@uri.scheme).to eq("http")
end
it "should have an authority segment of 'example.com'" do
expect(@uri.authority).to eq("example.com")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have no username" do
expect(@uri.user).to eq(nil)
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a path of '/file.txt;x=y'" do
expect(@uri.path).to eq("/file.txt;x=y")
end
it "should have an extname of '.txt'" do
expect(@uri.extname).to eq(".txt")
end
it "should have no query string" do
expect(@uri.query).to eq(nil)
end
it "should have no fragment" do
expect(@uri.fragment).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
end
describe Addressable::URI, "when parsed from " +
"'svn+ssh://developername@rubyforge.org/var/svn/project'" do
before do
@uri = Addressable::URI.parse(
"svn+ssh://developername@rubyforge.org/var/svn/project"
)
end
it "should have a scheme of 'svn+ssh'" do
expect(@uri.scheme).to eq("svn+ssh")
end
it "should be considered to be ip-based" do
expect(@uri).to be_ip_based
end
it "should have a path of '/var/svn/project'" do
expect(@uri.path).to eq("/var/svn/project")
end
it "should have a username of 'developername'" do
expect(@uri.user).to eq("developername")
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
end
describe Addressable::URI, "when parsed from " +
"'ssh+svn://developername@RUBYFORGE.ORG/var/svn/project'" do
before do
@uri = Addressable::URI.parse(
"ssh+svn://developername@RUBYFORGE.ORG/var/svn/project"
)
end
it "should have a scheme of 'ssh+svn'" do
expect(@uri.scheme).to eq("ssh+svn")
end
it "should have a normalized scheme of 'svn+ssh'" do
expect(@uri.normalized_scheme).to eq("svn+ssh")
end
it "should have a normalized site of 'svn+ssh'" do
expect(@uri.normalized_site).to eq("svn+ssh://developername@rubyforge.org")
end
it "should not be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should have a path of '/var/svn/project'" do
expect(@uri.path).to eq("/var/svn/project")
end
it "should have a username of 'developername'" do
expect(@uri.user).to eq("developername")
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should not be considered to be in normal form" do
expect(@uri.normalize).not_to be_eql(@uri)
end
end
describe Addressable::URI, "when parsed from " +
"'mailto:user@example.com'" do
before do
@uri = Addressable::URI.parse("mailto:user@example.com")
end
it "should have a scheme of 'mailto'" do
expect(@uri.scheme).to eq("mailto")
end
it "should not be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should have a path of 'user@example.com'" do
expect(@uri.path).to eq("user@example.com")
end
it "should have no user" do
expect(@uri.user).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
end
describe Addressable::URI, "when parsed from " +
"'tag:example.com,2006-08-18:/path/to/something'" do
before do
@uri = Addressable::URI.parse(
"tag:example.com,2006-08-18:/path/to/something")
end
it "should have a scheme of 'tag'" do
expect(@uri.scheme).to eq("tag")
end
it "should be considered to be ip-based" do
expect(@uri).not_to be_ip_based
end
it "should have a path of " +
"'example.com,2006-08-18:/path/to/something'" do
expect(@uri.path).to eq("example.com,2006-08-18:/path/to/something")
end
it "should have no user" do
expect(@uri.user).to eq(nil)
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/x;y/'" do
before do
@uri = Addressable::URI.parse("http://example.com/x;y/")
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?x=1&y=2'" do
before do
@uri = Addressable::URI.parse("http://example.com/?x=1&y=2")
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
end
describe Addressable::URI, "when parsed from " +
"'view-source:http://example.com/'" do
before do
@uri = Addressable::URI.parse("view-source:http://example.com/")
end
it "should have a scheme of 'view-source'" do
expect(@uri.scheme).to eq("view-source")
end
it "should have a path of 'http://example.com/'" do
expect(@uri.path).to eq("http://example.com/")
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from " +
"'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
before do
@uri = Addressable::URI.parse(
"http://user:pass@example.com/path/to/resource?query=x#fragment")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have an authority segment of 'user:pass@example.com'" do
expect(@uri.authority).to eq("user:pass@example.com")
end
it "should have a username of 'user'" do
expect(@uri.user).to eq("user")
end
it "should have a password of 'pass'" do
expect(@uri.password).to eq("pass")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a path of '/path/to/resource'" do
expect(@uri.path).to eq("/path/to/resource")
end
it "should have a query string of 'query=x'" do
expect(@uri.query).to eq("query=x")
end
it "should have a fragment of 'fragment'" do
expect(@uri.fragment).to eq("fragment")
end
it "should be considered to be in normal form" do
expect(@uri.normalize).to be_eql(@uri)
end
it "should have a route of '../../' to " +
"'http://user:pass@example.com/path/'" do
expect(@uri.route_to("http://user:pass@example.com/path/")).to eq(
Addressable::URI.parse("../../")
)
end
it "should have a route of 'to/resource?query=x#fragment' " +
"from 'http://user:pass@example.com/path/'" do
expect(@uri.route_from("http://user:pass@example.com/path/")).to eq(
Addressable::URI.parse("to/resource?query=x#fragment")
)
end
it "should have a route of '?query=x#fragment' " +
"from 'http://user:pass@example.com/path/to/resource'" do
expect(@uri.route_from("http://user:pass@example.com/path/to/resource")).to eq(
Addressable::URI.parse("?query=x#fragment")
)
end
it "should have a route of '#fragment' " +
"from 'http://user:pass@example.com/path/to/resource?query=x'" do
expect(@uri.route_from(
"http://user:pass@example.com/path/to/resource?query=x")).to eq(
Addressable::URI.parse("#fragment")
)
end
it "should have a route of '#fragment' from " +
"'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
expect(@uri.route_from(
"http://user:pass@example.com/path/to/resource?query=x#fragment"
)).to eq(Addressable::URI.parse("#fragment"))
end
it "should have a route of 'http://elsewhere.com/' to " +
"'http://elsewhere.com/'" do
expect(@uri.route_to("http://elsewhere.com/")).to eq(
Addressable::URI.parse("http://elsewhere.com/")
)
end
it "should have a route of " +
"'http://user:pass@example.com/path/to/resource?query=x#fragment' " +
"from 'http://example.com/path/to/'" do
expect(@uri.route_from("http://elsewhere.com/path/to/")).to eq(
Addressable::URI.parse(
"http://user:pass@example.com/path/to/resource?query=x#fragment")
)
end
it "should have the correct scheme after assignment" do
@uri.scheme = "ftp"
expect(@uri.scheme).to eq("ftp")
expect(@uri.to_s).to eq(
"ftp://user:pass@example.com/path/to/resource?query=x#fragment"
)
expect(@uri.to_str).to eq(
"ftp://user:pass@example.com/path/to/resource?query=x#fragment"
)
end
it "should have the correct site segment after assignment" do
@uri.site = "https://newuser:newpass@example.com:443"
expect(@uri.scheme).to eq("https")
expect(@uri.authority).to eq("newuser:newpass@example.com:443")
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq("newpass")
expect(@uri.userinfo).to eq("newuser:newpass")
expect(@uri.normalized_userinfo).to eq("newuser:newpass")
expect(@uri.host).to eq("example.com")
expect(@uri.port).to eq(443)
expect(@uri.inferred_port).to eq(443)
expect(@uri.to_s).to eq(
"https://newuser:newpass@example.com:443" +
"/path/to/resource?query=x#fragment"
)
end
it "should have the correct authority segment after assignment" do
@uri.authority = "newuser:newpass@example.com:80"
expect(@uri.authority).to eq("newuser:newpass@example.com:80")
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq("newpass")
expect(@uri.userinfo).to eq("newuser:newpass")
expect(@uri.normalized_userinfo).to eq("newuser:newpass")
expect(@uri.host).to eq("example.com")
expect(@uri.port).to eq(80)
expect(@uri.inferred_port).to eq(80)
expect(@uri.to_s).to eq(
"http://newuser:newpass@example.com:80" +
"/path/to/resource?query=x#fragment"
)
end
it "should have the correct userinfo segment after assignment" do
@uri.userinfo = "newuser:newpass"
expect(@uri.userinfo).to eq("newuser:newpass")
expect(@uri.authority).to eq("newuser:newpass@example.com")
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq("newpass")
expect(@uri.host).to eq("example.com")
expect(@uri.port).to eq(nil)
expect(@uri.inferred_port).to eq(80)
expect(@uri.to_s).to eq(
"http://newuser:newpass@example.com" +
"/path/to/resource?query=x#fragment"
)
end
it "should have the correct username after assignment" do
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
expect(@uri.authority).to eq("newuser:pass@example.com")
end
it "should have the correct password after assignment" do
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
expect(@uri.authority).to eq("user:newpass@example.com")
end
it "should have the correct host after assignment" do
@uri.host = "newexample.com"
expect(@uri.host).to eq("newexample.com")
expect(@uri.authority).to eq("user:pass@newexample.com")
end
it "should have the correct host after assignment" do
@uri.hostname = "newexample.com"
expect(@uri.host).to eq("newexample.com")
expect(@uri.hostname).to eq("newexample.com")
expect(@uri.authority).to eq("user:pass@newexample.com")
end
it "should raise an error if assigning a bogus object to the hostname" do
expect(lambda do
@uri.hostname = Object.new
end).to raise_error(TypeError)
end
it "should have the correct port after assignment" do
@uri.port = 8080
expect(@uri.port).to eq(8080)
expect(@uri.authority).to eq("user:pass@example.com:8080")
end
it "should have the correct origin after assignment" do
@uri.origin = "http://newexample.com"
expect(@uri.host).to eq("newexample.com")
expect(@uri.authority).to eq("newexample.com")
end
it "should have the correct path after assignment" do
@uri.path = "/newpath/to/resource"
expect(@uri.path).to eq("/newpath/to/resource")
expect(@uri.to_s).to eq(
"http://user:pass@example.com/newpath/to/resource?query=x#fragment"
)
end
it "should have the correct scheme and authority after nil assignment" do
@uri.site = nil
expect(@uri.scheme).to eq(nil)
expect(@uri.authority).to eq(nil)
expect(@uri.to_s).to eq("/path/to/resource?query=x#fragment")
end
it "should have the correct scheme and authority after assignment" do
@uri.site = "file://"
expect(@uri.scheme).to eq("file")
expect(@uri.authority).to eq("")
expect(@uri.to_s).to eq("file:///path/to/resource?query=x#fragment")
end
it "should have the correct path after nil assignment" do
@uri.path = nil
expect(@uri.path).to eq("")
expect(@uri.to_s).to eq(
"http://user:pass@example.com?query=x#fragment"
)
end
it "should have the correct query string after assignment" do
@uri.query = "newquery=x"
expect(@uri.query).to eq("newquery=x")
expect(@uri.to_s).to eq(
"http://user:pass@example.com/path/to/resource?newquery=x#fragment"
)
@uri.query = nil
expect(@uri.query).to eq(nil)
expect(@uri.to_s).to eq(
"http://user:pass@example.com/path/to/resource#fragment"
)
end
it "should have the correct query string after hash assignment" do
@uri.query_values = {"?uestion mark" => "=sign", "hello" => "g\xC3\xBCnther"}
expect(@uri.query.split("&")).to include("%3Fuestion%20mark=%3Dsign")
expect(@uri.query.split("&")).to include("hello=g%C3%BCnther")
expect(@uri.query_values).to eq({
"?uestion mark" => "=sign", "hello" => "g\xC3\xBCnther"
})
end
it "should have the correct query string after flag hash assignment" do
@uri.query_values = {'flag?1' => nil, 'fl=ag2' => nil, 'flag3' => nil}
expect(@uri.query.split("&")).to include("flag%3F1")
expect(@uri.query.split("&")).to include("fl%3Dag2")
expect(@uri.query.split("&")).to include("flag3")
expect(@uri.query_values(Array).sort).to eq([["fl=ag2"], ["flag3"], ["flag?1"]])
expect(@uri.query_values(Hash)).to eq({
'flag?1' => nil, 'fl=ag2' => nil, 'flag3' => nil
})
end
it "should raise an error if query values are set to a bogus type" do
expect(lambda do
@uri.query_values = "bogus"
end).to raise_error(TypeError)
end
it "should have the correct fragment after assignment" do
@uri.fragment = "newfragment"
expect(@uri.fragment).to eq("newfragment")
expect(@uri.to_s).to eq(
"http://user:pass@example.com/path/to/resource?query=x#newfragment"
)
@uri.fragment = nil
expect(@uri.fragment).to eq(nil)
expect(@uri.to_s).to eq(
"http://user:pass@example.com/path/to/resource?query=x"
)
end
it "should have the correct values after a merge" do
expect(@uri.merge(:fragment => "newfragment").to_s).to eq(
"http://user:pass@example.com/path/to/resource?query=x#newfragment"
)
end
it "should have the correct values after a merge" do
expect(@uri.merge(:fragment => nil).to_s).to eq(
"http://user:pass@example.com/path/to/resource?query=x"
)
end
it "should have the correct values after a merge" do
expect(@uri.merge(:userinfo => "newuser:newpass").to_s).to eq(
"http://newuser:newpass@example.com/path/to/resource?query=x#fragment"
)
end
it "should have the correct values after a merge" do
expect(@uri.merge(:userinfo => nil).to_s).to eq(
"http://example.com/path/to/resource?query=x#fragment"
)
end
it "should have the correct values after a merge" do
expect(@uri.merge(:path => "newpath").to_s).to eq(
"http://user:pass@example.com/newpath?query=x#fragment"
)
end
it "should have the correct values after a merge" do
expect(@uri.merge(:port => "42", :path => "newpath", :query => "").to_s).to eq(
"http://user:pass@example.com:42/newpath?#fragment"
)
end
it "should have the correct values after a merge" do
expect(@uri.merge(:authority => "foo:bar@baz:42").to_s).to eq(
"http://foo:bar@baz:42/path/to/resource?query=x#fragment"
)
# Ensure the operation was not destructive
expect(@uri.to_s).to eq(
"http://user:pass@example.com/path/to/resource?query=x#fragment"
)
end
it "should have the correct values after a destructive merge" do
@uri.merge!(:authority => "foo:bar@baz:42")
# Ensure the operation was destructive
expect(@uri.to_s).to eq(
"http://foo:bar@baz:42/path/to/resource?query=x#fragment"
)
end
it "should fail to merge with bogus values" do
expect(lambda do
@uri.merge(:port => "bogus")
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should fail to merge with bogus values" do
expect(lambda do
@uri.merge(:authority => "bar@baz:bogus")
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should fail to merge with bogus parameters" do
expect(lambda do
@uri.merge(42)
end).to raise_error(TypeError)
end
it "should fail to merge with bogus parameters" do
expect(lambda do
@uri.merge("http://example.com/")
end).to raise_error(TypeError)
end
it "should fail to merge with both authority and subcomponents" do
expect(lambda do
@uri.merge(:authority => "foo:bar@baz:42", :port => "42")
end).to raise_error(ArgumentError)
end
it "should fail to merge with both userinfo and subcomponents" do
expect(lambda do
@uri.merge(:userinfo => "foo:bar", :user => "foo")
end).to raise_error(ArgumentError)
end
it "should be identical to its duplicate" do
expect(@uri).to eq(@uri.dup)
end
it "should have an origin of 'http://example.com'" do
expect(@uri.origin).to eq('http://example.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/search?q=Q%26A'" do
before do
@uri = Addressable::URI.parse("http://example.com/search?q=Q%26A")
end
it "should have a query of 'q=Q%26A'" do
expect(@uri.query).to eq("q=Q%26A")
end
it "should have query_values of {'q' => 'Q&A'}" do
expect(@uri.query_values).to eq({ 'q' => 'Q&A' })
end
it "should normalize to the original uri " +
"(with the ampersand properly percent-encoded)" do
expect(@uri.normalize.to_s).to eq("http://example.com/search?q=Q%26A")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?&x=b'" do
before do
@uri = Addressable::URI.parse("http://example.com/?&x=b")
end
it "should have a query of '&x=b'" do
expect(@uri.query).to eq("&x=b")
end
it "should have query_values of {'x' => 'b'}" do
expect(@uri.query_values).to eq({'x' => 'b'})
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?q='one;two'&x=1'" do
before do
@uri = Addressable::URI.parse("http://example.com/?q='one;two'&x=1")
end
it "should have a query of 'q='one;two'&x=1'" do
expect(@uri.query).to eq("q='one;two'&x=1")
end
it "should have query_values of {\"q\" => \"'one;two'\", \"x\" => \"1\"}" do
expect(@uri.query_values).to eq({"q" => "'one;two'", "x" => "1"})
end
it "should escape the ';' character when normalizing to avoid ambiguity " +
"with the W3C HTML 4.01 specification" do
# HTML 4.01 Section B.2.2
expect(@uri.normalize.query).to eq("q='one%3Btwo'&x=1")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?&&x=b'" do
before do
@uri = Addressable::URI.parse("http://example.com/?&&x=b")
end
it "should have a query of '&&x=b'" do
expect(@uri.query).to eq("&&x=b")
end
it "should have query_values of {'x' => 'b'}" do
expect(@uri.query_values).to eq({'x' => 'b'})
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?q=a&&x=b'" do
before do
@uri = Addressable::URI.parse("http://example.com/?q=a&&x=b")
end
it "should have a query of 'q=a&&x=b'" do
expect(@uri.query).to eq("q=a&&x=b")
end
it "should have query_values of {'q' => 'a, 'x' => 'b'}" do
expect(@uri.query_values).to eq({'q' => 'a', 'x' => 'b'})
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?q&&x=b'" do
before do
@uri = Addressable::URI.parse("http://example.com/?q&&x=b")
end
it "should have a query of 'q&&x=b'" do
expect(@uri.query).to eq("q&&x=b")
end
it "should have query_values of {'q' => true, 'x' => 'b'}" do
expect(@uri.query_values).to eq({'q' => nil, 'x' => 'b'})
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?q=a+b'" do
before do
@uri = Addressable::URI.parse("http://example.com/?q=a+b")
end
it "should have a query of 'q=a+b'" do
expect(@uri.query).to eq("q=a+b")
end
it "should have query_values of {'q' => 'a b'}" do
expect(@uri.query_values).to eq({'q' => 'a b'})
end
it "should have a normalized query of 'q=a+b'" do
expect(@uri.normalized_query).to eq("q=a+b")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?q=a%2bb'" do
before do
@uri = Addressable::URI.parse("http://example.com/?q=a%2bb")
end
it "should have a query of 'q=a+b'" do
expect(@uri.query).to eq("q=a%2bb")
end
it "should have query_values of {'q' => 'a+b'}" do
expect(@uri.query_values).to eq({'q' => 'a+b'})
end
it "should have a normalized query of 'q=a%2Bb'" do
expect(@uri.normalized_query).to eq("q=a%2Bb")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?v=%7E&w=%&x=%25&y=%2B&z=C%CC%A7'" do
before do
@uri = Addressable::URI.parse("http://example.com/?v=%7E&w=%&x=%25&y=%2B&z=C%CC%A7")
end
it "should have a normalized query of 'v=~&w=%25&x=%25&y=%2B&z=%C3%87'" do
expect(@uri.normalized_query).to eq("v=~&w=%25&x=%25&y=%2B&z=%C3%87")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?v=%7E&w=%&x=%25&y=+&z=C%CC%A7'" do
before do
@uri = Addressable::URI.parse("http://example.com/?v=%7E&w=%&x=%25&y=+&z=C%CC%A7")
end
it "should have a normalized query of 'v=~&w=%25&x=%25&y=+&z=%C3%87'" do
expect(@uri.normalized_query).to eq("v=~&w=%25&x=%25&y=+&z=%C3%87")
end
end
describe Addressable::URI, "when parsed from 'http://example/?b=1&a=2&c=3'" do
before do
@uri = Addressable::URI.parse("http://example/?b=1&a=2&c=3")
end
it "should have a sorted normalized query of 'a=2&b=1&c=3'" do
expect(@uri.normalized_query(:sorted)).to eq("a=2&b=1&c=3")
end
end
describe Addressable::URI, "when parsed from 'http://example/?&a&&c&'" do
before do
@uri = Addressable::URI.parse("http://example/?&a&&c&")
end
it "should have a compacted normalized query of 'a&c'" do
expect(@uri.normalized_query(:compacted)).to eq("a&c")
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/sound%2bvision'" do
before do
@uri = Addressable::URI.parse("http://example.com/sound%2bvision")
end
it "should have a normalized path of '/sound+vision'" do
expect(@uri.normalized_path).to eq('/sound+vision')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/?q='" do
before do
@uri = Addressable::URI.parse("http://example.com/?q=")
end
it "should have a query of 'q='" do
expect(@uri.query).to eq("q=")
end
it "should have query_values of {'q' => ''}" do
expect(@uri.query_values).to eq({'q' => ''})
end
end
describe Addressable::URI, "when parsed from " +
"'http://user@example.com'" do
before do
@uri = Addressable::URI.parse("http://user@example.com")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have a username of 'user'" do
expect(@uri.user).to eq("user")
end
it "should have no password" do
expect(@uri.password).to eq(nil)
end
it "should have a userinfo of 'user'" do
expect(@uri.userinfo).to eq("user")
end
it "should have a normalized userinfo of 'user'" do
expect(@uri.normalized_userinfo).to eq("user")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have default_port 80" do
expect(@uri.default_port).to eq(80)
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have the correct username after assignment" do
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq(nil)
expect(@uri.to_s).to eq("http://newuser@example.com")
end
it "should have the correct password after assignment" do
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
expect(@uri.to_s).to eq("http://user:newpass@example.com")
end
it "should have the correct userinfo segment after assignment" do
@uri.userinfo = "newuser:newpass"
expect(@uri.userinfo).to eq("newuser:newpass")
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq("newpass")
expect(@uri.host).to eq("example.com")
expect(@uri.port).to eq(nil)
expect(@uri.inferred_port).to eq(80)
expect(@uri.to_s).to eq("http://newuser:newpass@example.com")
end
it "should have the correct userinfo segment after nil assignment" do
@uri.userinfo = nil
expect(@uri.userinfo).to eq(nil)
expect(@uri.user).to eq(nil)
expect(@uri.password).to eq(nil)
expect(@uri.host).to eq("example.com")
expect(@uri.port).to eq(nil)
expect(@uri.inferred_port).to eq(80)
expect(@uri.to_s).to eq("http://example.com")
end
it "should have the correct authority segment after assignment" do
@uri.authority = "newuser@example.com"
expect(@uri.authority).to eq("newuser@example.com")
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq(nil)
expect(@uri.host).to eq("example.com")
expect(@uri.port).to eq(nil)
expect(@uri.inferred_port).to eq(80)
expect(@uri.to_s).to eq("http://newuser@example.com")
end
it "should raise an error after nil assignment of authority segment" do
expect(lambda do
# This would create an invalid URI
@uri.authority = nil
end).to raise_error(Addressable::URI::InvalidURIError)
end
end
describe Addressable::URI, "when parsed from " +
"'http://user:@example.com'" do
before do
@uri = Addressable::URI.parse("http://user:@example.com")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have a username of 'user'" do
expect(@uri.user).to eq("user")
end
it "should have a password of ''" do
expect(@uri.password).to eq("")
end
it "should have a normalized userinfo of 'user:'" do
expect(@uri.normalized_userinfo).to eq("user:")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have the correct username after assignment" do
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq("")
expect(@uri.to_s).to eq("http://newuser:@example.com")
end
it "should have the correct password after assignment" do
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
expect(@uri.to_s).to eq("http://user:newpass@example.com")
end
it "should have the correct authority segment after assignment" do
@uri.authority = "newuser:@example.com"
expect(@uri.authority).to eq("newuser:@example.com")
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq("")
expect(@uri.host).to eq("example.com")
expect(@uri.port).to eq(nil)
expect(@uri.inferred_port).to eq(80)
expect(@uri.to_s).to eq("http://newuser:@example.com")
end
end
describe Addressable::URI, "when parsed from " +
"'http://:pass@example.com'" do
before do
@uri = Addressable::URI.parse("http://:pass@example.com")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have a username of ''" do
expect(@uri.user).to eq("")
end
it "should have a password of 'pass'" do
expect(@uri.password).to eq("pass")
end
it "should have a userinfo of ':pass'" do
expect(@uri.userinfo).to eq(":pass")
end
it "should have a normalized userinfo of ':pass'" do
expect(@uri.normalized_userinfo).to eq(":pass")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have the correct username after assignment" do
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq("pass")
expect(@uri.to_s).to eq("http://newuser:pass@example.com")
end
it "should have the correct password after assignment" do
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
expect(@uri.user).to eq("")
expect(@uri.to_s).to eq("http://:newpass@example.com")
end
it "should have the correct authority segment after assignment" do
@uri.authority = ":newpass@example.com"
expect(@uri.authority).to eq(":newpass@example.com")
expect(@uri.user).to eq("")
expect(@uri.password).to eq("newpass")
expect(@uri.host).to eq("example.com")
expect(@uri.port).to eq(nil)
expect(@uri.inferred_port).to eq(80)
expect(@uri.to_s).to eq("http://:newpass@example.com")
end
end
describe Addressable::URI, "when parsed from " +
"'http://:@example.com'" do
before do
@uri = Addressable::URI.parse("http://:@example.com")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have a username of ''" do
expect(@uri.user).to eq("")
end
it "should have a password of ''" do
expect(@uri.password).to eq("")
end
it "should have a normalized userinfo of nil" do
expect(@uri.normalized_userinfo).to eq(nil)
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have the correct username after assignment" do
@uri.user = "newuser"
expect(@uri.user).to eq("newuser")
expect(@uri.password).to eq("")
expect(@uri.to_s).to eq("http://newuser:@example.com")
end
it "should have the correct password after assignment" do
@uri.password = "newpass"
expect(@uri.password).to eq("newpass")
expect(@uri.user).to eq("")
expect(@uri.to_s).to eq("http://:newpass@example.com")
end
it "should have the correct authority segment after assignment" do
@uri.authority = ":@newexample.com"
expect(@uri.authority).to eq(":@newexample.com")
expect(@uri.user).to eq("")
expect(@uri.password).to eq("")
expect(@uri.host).to eq("newexample.com")
expect(@uri.port).to eq(nil)
expect(@uri.inferred_port).to eq(80)
expect(@uri.to_s).to eq("http://:@newexample.com")
end
end
describe Addressable::URI, "when parsed from " +
"'#example'" do
before do
@uri = Addressable::URI.parse("#example")
end
it "should be considered relative" do
expect(@uri).to be_relative
end
it "should have a host of nil" do
expect(@uri.host).to eq(nil)
end
it "should have a site of nil" do
expect(@uri.site).to eq(nil)
end
it "should have a normalized_site of nil" do
expect(@uri.normalized_site).to eq(nil)
end
it "should have a path of ''" do
expect(@uri.path).to eq("")
end
it "should have a query string of nil" do
expect(@uri.query).to eq(nil)
end
it "should have a fragment of 'example'" do
expect(@uri.fragment).to eq("example")
end
end
describe Addressable::URI, "when parsed from " +
"the network-path reference '//example.com/'" do
before do
@uri = Addressable::URI.parse("//example.com/")
end
it "should be considered relative" do
expect(@uri).to be_relative
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should have a path of '/'" do
expect(@uri.path).to eq("/")
end
it "should raise an error if routing is attempted" do
expect(lambda do
@uri.route_to("http://example.com/")
end).to raise_error(ArgumentError, /\/\/example.com\//)
expect(lambda do
@uri.route_from("http://example.com/")
end).to raise_error(ArgumentError, /\/\/example.com\//)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from " +
"'feed://http://example.com/'" do
before do
@uri = Addressable::URI.parse("feed://http://example.com/")
end
it "should have a host of 'http'" do
expect(@uri.host).to eq("http")
end
it "should have a path of '//example.com/'" do
expect(@uri.path).to eq("//example.com/")
end
end
describe Addressable::URI, "when parsed from " +
"'feed:http://example.com/'" do
before do
@uri = Addressable::URI.parse("feed:http://example.com/")
end
it "should have a path of 'http://example.com/'" do
expect(@uri.path).to eq("http://example.com/")
end
it "should normalize to 'http://example.com/'" do
expect(@uri.normalize.to_s).to eq("http://example.com/")
expect(@uri.normalize!.to_s).to eq("http://example.com/")
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from " +
"'example://a/b/c/%7Bfoo%7D'" do
before do
@uri = Addressable::URI.parse("example://a/b/c/%7Bfoo%7D")
end
# Section 6.2.2 of RFC 3986
it "should be equivalent to eXAMPLE://a/./b/../b/%63/%7bfoo%7d" do
expect(@uri).to eq(
Addressable::URI.parse("eXAMPLE://a/./b/../b/%63/%7bfoo%7d")
)
end
it "should have an origin of 'example://a'" do
expect(@uri.origin).to eq('example://a')
end
end
describe Addressable::URI, "when parsed from " +
"'http://example.com/indirect/path/./to/../resource/'" do
before do
@uri = Addressable::URI.parse(
"http://example.com/indirect/path/./to/../resource/")
end
it "should use the 'http' scheme" do
expect(@uri.scheme).to eq("http")
end
it "should have a host of 'example.com'" do
expect(@uri.host).to eq("example.com")
end
it "should use port 80" do
expect(@uri.inferred_port).to eq(80)
end
it "should have a path of '/indirect/path/./to/../resource/'" do
expect(@uri.path).to eq("/indirect/path/./to/../resource/")
end
# Section 6.2.2.3 of RFC 3986
it "should have a normalized path of '/indirect/path/resource/'" do
expect(@uri.normalize.path).to eq("/indirect/path/resource/")
expect(@uri.normalize!.path).to eq("/indirect/path/resource/")
end
end
describe Addressable::URI, "when parsed from " +
"'http://under_score.example.com/'" do
it "should not cause an error" do
expect(lambda do
Addressable::URI.parse("http://under_score.example.com/")
end).not_to raise_error
end
end
describe Addressable::URI, "when parsed from " +
"'./this:that'" do
before do
@uri = Addressable::URI.parse("./this:that")
end
it "should be considered relative" do
expect(@uri).to be_relative
end
it "should have no scheme" do
expect(@uri.scheme).to eq(nil)
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from " +
"'this:that'" do
before do
@uri = Addressable::URI.parse("this:that")
end
it "should be considered absolute" do
expect(@uri).to be_absolute
end
it "should have a scheme of 'this'" do
expect(@uri.scheme).to eq("this")
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from '?'" do
before do
@uri = Addressable::URI.parse("?")
end
it "should normalize to ''" do
expect(@uri.normalize.to_s).to eq("")
end
it "should have the correct return type" do
expect(@uri.query_values).to eq({})
expect(@uri.query_values(Hash)).to eq({})
expect(@uri.query_values(Array)).to eq([])
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
before do
@uri = Addressable::URI.parse("?one=1&two=2&three=3")
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({"one" => "1", "two" => "2", "three" => "3"})
end
it "should raise an error for invalid return type values" do
expect(lambda do
@uri.query_values(Integer)
end).to raise_error(ArgumentError)
end
it "should have the correct array query values" do
expect(@uri.query_values(Array)).to eq([
["one", "1"], ["two", "2"], ["three", "3"]
])
end
it "should have a 'null' origin" do
expect(@uri.origin).to eq('null')
end
end
describe Addressable::URI, "when parsed from '?one=1=uno&two=2=dos'" do
before do
@uri = Addressable::URI.parse("?one=1=uno&two=2=dos")
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({"one" => "1=uno", "two" => "2=dos"})
end
it "should have the correct array query values" do
expect(@uri.query_values(Array)).to eq([
["one", "1=uno"], ["two", "2=dos"]
])
end
end
describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
before do
@uri = Addressable::URI.parse("?one[two][three]=four")
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({"one[two][three]" => "four"})
end
it "should have the correct array query values" do
expect(@uri.query_values(Array)).to eq([
["one[two][three]", "four"]
])
end
end
describe Addressable::URI, "when parsed from '?one.two.three=four'" do
before do
@uri = Addressable::URI.parse("?one.two.three=four")
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({
"one.two.three" => "four"
})
end
it "should have the correct array query values" do
expect(@uri.query_values(Array)).to eq([
["one.two.three", "four"]
])
end
end
describe Addressable::URI, "when parsed from " +
"'?one[two][three]=four&one[two][five]=six'" do
before do
@uri = Addressable::URI.parse("?one[two][three]=four&one[two][five]=six")
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({
"one[two][three]" => "four", "one[two][five]" => "six"
})
end
it "should have the correct array query values" do
expect(@uri.query_values(Array)).to eq([
["one[two][three]", "four"], ["one[two][five]", "six"]
])
end
end
describe Addressable::URI, "when parsed from " +
"'?one.two.three=four&one.two.five=six'" do
before do
@uri = Addressable::URI.parse("?one.two.three=four&one.two.five=six")
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({
"one.two.three" => "four", "one.two.five" => "six"
})
end
it "should have the correct array query values" do
expect(@uri.query_values(Array)).to eq([
["one.two.three", "four"], ["one.two.five", "six"]
])
end
end
describe Addressable::URI, "when parsed from " +
"'?one=two&one=three'" do
before do
@uri = Addressable::URI.parse(
"?one=two&one=three&one=four"
)
end
it "should have correct array query values" do
expect(@uri.query_values(Array)).to eq(
[['one', 'two'], ['one', 'three'], ['one', 'four']]
)
end
it "should have correct hash query values" do
skip("This is probably more desirable behavior.")
expect(@uri.query_values(Hash)).to eq(
{'one' => ['two', 'three', 'four']}
)
end
it "should handle assignment with keys of mixed type" do
@uri.query_values = @uri.query_values(Hash).merge({:one => 'three'})
expect(@uri.query_values(Hash)).to eq({'one' => 'three'})
end
end
describe Addressable::URI, "when parsed from " +
"'?one[two][three][]=four&one[two][three][]=five'" do
before do
@uri = Addressable::URI.parse(
"?one[two][three][]=four&one[two][three][]=five"
)
end
it "should have correct query values" do
expect(@uri.query_values(Hash)).to eq({"one[two][three][]" => "five"})
end
it "should have correct array query values" do
expect(@uri.query_values(Array)).to eq([
["one[two][three][]", "four"], ["one[two][three][]", "five"]
])
end
end
describe Addressable::URI, "when parsed from " +
"'?one[two][three][0]=four&one[two][three][1]=five'" do
before do
@uri = Addressable::URI.parse(
"?one[two][three][0]=four&one[two][three][1]=five"
)
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({
"one[two][three][0]" => "four", "one[two][three][1]" => "five"
})
end
end
describe Addressable::URI, "when parsed from " +
"'?one[two][three][1]=four&one[two][three][0]=five'" do
before do
@uri = Addressable::URI.parse(
"?one[two][three][1]=four&one[two][three][0]=five"
)
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({
"one[two][three][1]" => "four", "one[two][three][0]" => "five"
})
end
end
describe Addressable::URI, "when parsed from " +
"'?one[two][three][2]=four&one[two][three][1]=five'" do
before do
@uri = Addressable::URI.parse(
"?one[two][three][2]=four&one[two][three][1]=five"
)
end
it "should have the correct query values" do
expect(@uri.query_values).to eq({
"one[two][three][2]" => "four", "one[two][three][1]" => "five"
})
end
end
describe Addressable::URI, "when parsed from " +
"'http://www.詹姆斯.com/'" do
before do
@uri = Addressable::URI.parse("http://www.詹姆斯.com/")
end
it "should be equivalent to 'http://www.xn--8ws00zhy3a.com/'" do
expect(@uri).to eq(
Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
)
end
it "should not have domain name encoded during normalization" do
expect(Addressable::URI.normalized_encode(@uri.to_s)).to eq(
"http://www.詹姆斯.com/"
)
end
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
expect(@uri.origin).to eq('http://www.xn--8ws00zhy3a.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://www.詹姆斯.com/ some spaces /'" do
before do
@uri = Addressable::URI.parse("http://www.詹姆斯.com/ some spaces /")
end
it "should be equivalent to " +
"'http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/'" do
expect(@uri).to eq(
Addressable::URI.parse(
"http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/")
)
end
it "should not have domain name encoded during normalization" do
expect(Addressable::URI.normalized_encode(@uri.to_s)).to eq(
"http://www.詹姆斯.com/%20some%20spaces%20/"
)
end
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
expect(@uri.origin).to eq('http://www.xn--8ws00zhy3a.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://www.xn--8ws00zhy3a.com/'" do
before do
@uri = Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
end
it "should be displayed as http://www.詹姆斯.com/" do
expect(@uri.display_uri.to_s).to eq("http://www.詹姆斯.com/")
end
it "should properly force the encoding" do
display_string = @uri.display_uri.to_str
expect(display_string).to eq("http://www.詹姆斯.com/")
if display_string.respond_to?(:encoding)
expect(display_string.encoding.to_s).to eq(Encoding::UTF_8.to_s)
end
end
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
expect(@uri.origin).to eq('http://www.xn--8ws00zhy3a.com')
end
end
describe Addressable::URI, "when parsed from " +
"'http://www.詹姆斯.com/atomtests/iri/詹.html'" do
before do
@uri = Addressable::URI.parse("http://www.詹姆斯.com/atomtests/iri/詹.html")
end
it "should normalize to " +
"http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html" do
expect(@uri.normalize.to_s).to eq(
"http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
)
expect(@uri.normalize!.to_s).to eq(
"http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
)
end
end
describe Addressable::URI, "when parsed from a percent-encoded IRI" do
before do
@uri = Addressable::URI.parse(
"http://www.%E3%81%BB%E3%82%93%E3%81%A8%E3%81%86%E3%81%AB%E3%81%AA" +
"%E3%81%8C%E3%81%84%E3%82%8F%E3%81%91%E3%81%AE%E3%82%8F%E3%81%8B%E3" +
"%82%89%E3%81%AA%E3%81%84%E3%81%A9%E3%82%81%E3%81%84%E3%82%93%E3%82" +
"%81%E3%81%84%E3%81%AE%E3%82%89%E3%81%B9%E3%82%8B%E3%81%BE%E3%81%A0" +
"%E3%81%AA%E3%81%8C%E3%81%8F%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E3" +
"%81%9F%E3%82%8A%E3%81%AA%E3%81%84.w3.mag.keio.ac.jp"
)
end
it "should normalize to something sane" do
expect(@uri.normalize.to_s).to eq(
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/"
)
expect(@uri.normalize!.to_s).to eq(
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/"
)
end
it "should have the correct origin" do
expect(@uri.origin).to eq(
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
)
end
end
describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
before do
@uri = Addressable::URI.parse("http://a/b/c/d;p?q")
end
# Section 5.4.1 of RFC 3986
it "when joined with 'g:h' should resolve to g:h" do
expect((@uri + "g:h").to_s).to eq("g:h")
expect(Addressable::URI.join(@uri, "g:h").to_s).to eq("g:h")
end
# Section 5.4.1 of RFC 3986
it "when joined with 'g' should resolve to http://a/b/c/g" do
expect((@uri + "g").to_s).to eq("http://a/b/c/g")
expect(Addressable::URI.join(@uri.to_s, "g").to_s).to eq("http://a/b/c/g")
end
# Section 5.4.1 of RFC 3986
it "when joined with './g' should resolve to http://a/b/c/g" do
expect((@uri + "./g").to_s).to eq("http://a/b/c/g")
expect(Addressable::URI.join(@uri.to_s, "./g").to_s).to eq("http://a/b/c/g")
end
# Section 5.4.1 of RFC 3986
it "when joined with 'g/' should resolve to http://a/b/c/g/" do
expect((@uri + "g/").to_s).to eq("http://a/b/c/g/")
expect(Addressable::URI.join(@uri.to_s, "g/").to_s).to eq("http://a/b/c/g/")
end
# Section 5.4.1 of RFC 3986
it "when joined with '/g' should resolve to http://a/g" do
expect((@uri + "/g").to_s).to eq("http://a/g")
expect(Addressable::URI.join(@uri.to_s, "/g").to_s).to eq("http://a/g")
end
# Section 5.4.1 of RFC 3986
it "when joined with '//g' should resolve to http://g" do
expect((@uri + "//g").to_s).to eq("http://g")
expect(Addressable::URI.join(@uri.to_s, "//g").to_s).to eq("http://g")
end
# Section 5.4.1 of RFC 3986
it "when joined with '?y' should resolve to http://a/b/c/d;p?y" do
expect((@uri + "?y").to_s).to eq("http://a/b/c/d;p?y")
expect(Addressable::URI.join(@uri.to_s, "?y").to_s).to eq("http://a/b/c/d;p?y")
end
# Section 5.4.1 of RFC 3986
it "when joined with 'g?y' should resolve to http://a/b/c/g?y" do
expect((@uri + "g?y").to_s).to eq("http://a/b/c/g?y")
expect(Addressable::URI.join(@uri.to_s, "g?y").to_s).to eq("http://a/b/c/g?y")
end
# Section 5.4.1 of RFC 3986
it "when joined with '#s' should resolve to http://a/b/c/d;p?q#s" do
expect((@uri + "#s").to_s).to eq("http://a/b/c/d;p?q#s")
expect(Addressable::URI.join(@uri.to_s, "#s").to_s).to eq(
"http://a/b/c/d;p?q#s"
)
end
# Section 5.4.1 of RFC 3986
it "when joined with 'g#s' should resolve to http://a/b/c/g#s" do
expect((@uri + "g#s").to_s).to eq("http://a/b/c/g#s")
expect(Addressable::URI.join(@uri.to_s, "g#s").to_s).to eq("http://a/b/c/g#s")
end
# Section 5.4.1 of RFC 3986
it "when joined with 'g?y#s' should resolve to http://a/b/c/g?y#s" do
expect((@uri + "g?y#s").to_s).to eq("http://a/b/c/g?y#s")
expect(Addressable::URI.join(
@uri.to_s, "g?y#s").to_s).to eq("http://a/b/c/g?y#s")
end
# Section 5.4.1 of RFC 3986
it "when joined with ';x' should resolve to http://a/b/c/;x" do
expect((@uri + ";x").to_s).to eq("http://a/b/c/;x")
expect(Addressable::URI.join(@uri.to_s, ";x").to_s).to eq("http://a/b/c/;x")
end
# Section 5.4.1 of RFC 3986
it "when joined with 'g;x' should resolve to http://a/b/c/g;x" do
expect((@uri + "g;x").to_s).to eq("http://a/b/c/g;x")
expect(Addressable::URI.join(@uri.to_s, "g;x").to_s).to eq("http://a/b/c/g;x")
end
# Section 5.4.1 of RFC 3986
it "when joined with 'g;x?y#s' should resolve to http://a/b/c/g;x?y#s" do
expect((@uri + "g;x?y#s").to_s).to eq("http://a/b/c/g;x?y#s")
expect(Addressable::URI.join(
@uri.to_s, "g;x?y#s").to_s).to eq("http://a/b/c/g;x?y#s")
end
# Section 5.4.1 of RFC 3986
it "when joined with '' should resolve to http://a/b/c/d;p?q" do
expect((@uri + "").to_s).to eq("http://a/b/c/d;p?q")
expect(Addressable::URI.join(@uri.to_s, "").to_s).to eq("http://a/b/c/d;p?q")
end
# Section 5.4.1 of RFC 3986
it "when joined with '.' should resolve to http://a/b/c/" do
expect((@uri + ".").to_s).to eq("http://a/b/c/")
expect(Addressable::URI.join(@uri.to_s, ".").to_s).to eq("http://a/b/c/")
end
# Section 5.4.1 of RFC 3986
it "when joined with './' should resolve to http://a/b/c/" do
expect((@uri + "./").to_s).to eq("http://a/b/c/")
expect(Addressable::URI.join(@uri.to_s, "./").to_s).to eq("http://a/b/c/")
end
# Section 5.4.1 of RFC 3986
it "when joined with '..' should resolve to http://a/b/" do
expect((@uri + "..").to_s).to eq("http://a/b/")
expect(Addressable::URI.join(@uri.to_s, "..").to_s).to eq("http://a/b/")
end
# Section 5.4.1 of RFC 3986
it "when joined with '../' should resolve to http://a/b/" do
expect((@uri + "../").to_s).to eq("http://a/b/")
expect(Addressable::URI.join(@uri.to_s, "../").to_s).to eq("http://a/b/")
end
# Section 5.4.1 of RFC 3986
it "when joined with '../g' should resolve to http://a/b/g" do
expect((@uri + "../g").to_s).to eq("http://a/b/g")
expect(Addressable::URI.join(@uri.to_s, "../g").to_s).to eq("http://a/b/g")
end
# Section 5.4.1 of RFC 3986
it "when joined with '../..' should resolve to http://a/" do
expect((@uri + "../..").to_s).to eq("http://a/")
expect(Addressable::URI.join(@uri.to_s, "../..").to_s).to eq("http://a/")
end
# Section 5.4.1 of RFC 3986
it "when joined with '../../' should resolve to http://a/" do
expect((@uri + "../../").to_s).to eq("http://a/")
expect(Addressable::URI.join(@uri.to_s, "../../").to_s).to eq("http://a/")
end
# Section 5.4.1 of RFC 3986
it "when joined with '../../g' should resolve to http://a/g" do
expect((@uri + "../../g").to_s).to eq("http://a/g")
expect(Addressable::URI.join(@uri.to_s, "../../g").to_s).to eq("http://a/g")
end
# Section 5.4.2 of RFC 3986
it "when joined with '../../../g' should resolve to http://a/g" do
expect((@uri + "../../../g").to_s).to eq("http://a/g")
expect(Addressable::URI.join(@uri.to_s, "../../../g").to_s).to eq("http://a/g")
end
it "when joined with '../.././../g' should resolve to http://a/g" do
expect((@uri + "../.././../g").to_s).to eq("http://a/g")
expect(Addressable::URI.join(@uri.to_s, "../.././../g").to_s).to eq(
"http://a/g"
)
end
# Section 5.4.2 of RFC 3986
it "when joined with '../../../../g' should resolve to http://a/g" do
expect((@uri + "../../../../g").to_s).to eq("http://a/g")
expect(Addressable::URI.join(
@uri.to_s, "../../../../g").to_s).to eq("http://a/g")
end
# Section 5.4.2 of RFC 3986
it "when joined with '/./g' should resolve to http://a/g" do
expect((@uri + "/./g").to_s).to eq("http://a/g")
expect(Addressable::URI.join(@uri.to_s, "/./g").to_s).to eq("http://a/g")
end
# Section 5.4.2 of RFC 3986
it "when joined with '/../g' should resolve to http://a/g" do
expect((@uri + "/../g").to_s).to eq("http://a/g")
expect(Addressable::URI.join(@uri.to_s, "/../g").to_s).to eq("http://a/g")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g.' should resolve to http://a/b/c/g." do
expect((@uri + "g.").to_s).to eq("http://a/b/c/g.")
expect(Addressable::URI.join(@uri.to_s, "g.").to_s).to eq("http://a/b/c/g.")
end
# Section 5.4.2 of RFC 3986
it "when joined with '.g' should resolve to http://a/b/c/.g" do
expect((@uri + ".g").to_s).to eq("http://a/b/c/.g")
expect(Addressable::URI.join(@uri.to_s, ".g").to_s).to eq("http://a/b/c/.g")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g..' should resolve to http://a/b/c/g.." do
expect((@uri + "g..").to_s).to eq("http://a/b/c/g..")
expect(Addressable::URI.join(@uri.to_s, "g..").to_s).to eq("http://a/b/c/g..")
end
# Section 5.4.2 of RFC 3986
it "when joined with '..g' should resolve to http://a/b/c/..g" do
expect((@uri + "..g").to_s).to eq("http://a/b/c/..g")
expect(Addressable::URI.join(@uri.to_s, "..g").to_s).to eq("http://a/b/c/..g")
end
# Section 5.4.2 of RFC 3986
it "when joined with './../g' should resolve to http://a/b/g" do
expect((@uri + "./../g").to_s).to eq("http://a/b/g")
expect(Addressable::URI.join(@uri.to_s, "./../g").to_s).to eq("http://a/b/g")
end
# Section 5.4.2 of RFC 3986
it "when joined with './g/.' should resolve to http://a/b/c/g/" do
expect((@uri + "./g/.").to_s).to eq("http://a/b/c/g/")
expect(Addressable::URI.join(@uri.to_s, "./g/.").to_s).to eq("http://a/b/c/g/")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g/./h' should resolve to http://a/b/c/g/h" do
expect((@uri + "g/./h").to_s).to eq("http://a/b/c/g/h")
expect(Addressable::URI.join(@uri.to_s, "g/./h").to_s).to eq("http://a/b/c/g/h")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g/../h' should resolve to http://a/b/c/h" do
expect((@uri + "g/../h").to_s).to eq("http://a/b/c/h")
expect(Addressable::URI.join(@uri.to_s, "g/../h").to_s).to eq("http://a/b/c/h")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g;x=1/./y' " +
"should resolve to http://a/b/c/g;x=1/y" do
expect((@uri + "g;x=1/./y").to_s).to eq("http://a/b/c/g;x=1/y")
expect(Addressable::URI.join(
@uri.to_s, "g;x=1/./y").to_s).to eq("http://a/b/c/g;x=1/y")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g;x=1/../y' should resolve to http://a/b/c/y" do
expect((@uri + "g;x=1/../y").to_s).to eq("http://a/b/c/y")
expect(Addressable::URI.join(
@uri.to_s, "g;x=1/../y").to_s).to eq("http://a/b/c/y")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g?y/./x' " +
"should resolve to http://a/b/c/g?y/./x" do
expect((@uri + "g?y/./x").to_s).to eq("http://a/b/c/g?y/./x")
expect(Addressable::URI.join(
@uri.to_s, "g?y/./x").to_s).to eq("http://a/b/c/g?y/./x")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g?y/../x' " +
"should resolve to http://a/b/c/g?y/../x" do
expect((@uri + "g?y/../x").to_s).to eq("http://a/b/c/g?y/../x")
expect(Addressable::URI.join(
@uri.to_s, "g?y/../x").to_s).to eq("http://a/b/c/g?y/../x")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g#s/./x' " +
"should resolve to http://a/b/c/g#s/./x" do
expect((@uri + "g#s/./x").to_s).to eq("http://a/b/c/g#s/./x")
expect(Addressable::URI.join(
@uri.to_s, "g#s/./x").to_s).to eq("http://a/b/c/g#s/./x")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'g#s/../x' " +
"should resolve to http://a/b/c/g#s/../x" do
expect((@uri + "g#s/../x").to_s).to eq("http://a/b/c/g#s/../x")
expect(Addressable::URI.join(
@uri.to_s, "g#s/../x").to_s).to eq("http://a/b/c/g#s/../x")
end
# Section 5.4.2 of RFC 3986
it "when joined with 'http:g' should resolve to http:g" do
expect((@uri + "http:g").to_s).to eq("http:g")
expect(Addressable::URI.join(@uri.to_s, "http:g").to_s).to eq("http:g")
end
# Edge case to be sure
it "when joined with '//example.com/' should " +
"resolve to http://example.com/" do
expect((@uri + "//example.com/").to_s).to eq("http://example.com/")
expect(Addressable::URI.join(
@uri.to_s, "//example.com/").to_s).to eq("http://example.com/")
end
it "when joined with a bogus object a TypeError should be raised" do
expect(lambda do
Addressable::URI.join(@uri, 42)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when converting the path " +
"'relative/path/to/something'" do
before do
@path = 'relative/path/to/something'
end
it "should convert to " +
"\'relative/path/to/something\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("relative/path/to/something")
end
it "should join with an absolute file path correctly" do
@base = Addressable::URI.convert_path("/absolute/path/")
@uri = Addressable::URI.convert_path(@path)
expect((@base + @uri).to_str).to eq(
"file:///absolute/path/relative/path/to/something"
)
end
end
describe Addressable::URI, "when converting a bogus path" do
it "should raise a TypeError" do
expect(lambda do
Addressable::URI.convert_path(42)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when given a UNIX root directory" do
before do
@path = "/"
end
it "should convert to \'file:///\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("file:///")
end
it "should have an origin of 'file://'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.origin).to eq('file://')
end
end
describe Addressable::URI, "when given a Windows root directory" do
before do
@path = "C:\\"
end
it "should convert to \'file:///c:/\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("file:///c:/")
end
it "should have an origin of 'file://'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.origin).to eq('file://')
end
end
describe Addressable::URI, "when given the path '/one/two/'" do
before do
@path = '/one/two/'
end
it "should convert to " +
"\'file:///one/two/\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("file:///one/two/")
end
it "should have an origin of 'file://'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.origin).to eq('file://')
end
end
describe Addressable::URI, "when given the tld " do
it "'uk' should have a tld of 'uk'" do
uri = Addressable::URI.parse("http://example.com")
uri.tld = "uk"
expect(uri.tld).to eq("uk")
end
context "which " do
let (:uri) { Addressable::URI.parse("http://www.comrade.net/path/to/source/") }
it "contains a subdomain" do
uri.tld = "co.uk"
expect(uri.to_s).to eq("http://www.comrade.co.uk/path/to/source/")
end
it "is part of the domain" do
uri.tld = "com"
expect(uri.to_s).to eq("http://www.comrade.com/path/to/source/")
end
end
end
describe Addressable::URI, "when given the path " +
"'c:\\windows\\My Documents 100%20\\foo.txt'" do
before do
@path = "c:\\windows\\My Documents 100%20\\foo.txt"
end
it "should convert to " +
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("file:///c:/windows/My%20Documents%20100%20/foo.txt")
end
it "should have an origin of 'file://'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.origin).to eq('file://')
end
end
describe Addressable::URI, "when given the path " +
"'file://c:\\windows\\My Documents 100%20\\foo.txt'" do
before do
@path = "file://c:\\windows\\My Documents 100%20\\foo.txt"
end
it "should convert to " +
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("file:///c:/windows/My%20Documents%20100%20/foo.txt")
end
it "should have an origin of 'file://'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.origin).to eq('file://')
end
end
describe Addressable::URI, "when given the path " +
"'file:c:\\windows\\My Documents 100%20\\foo.txt'" do
before do
@path = "file:c:\\windows\\My Documents 100%20\\foo.txt"
end
it "should convert to " +
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("file:///c:/windows/My%20Documents%20100%20/foo.txt")
end
it "should have an origin of 'file://'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.origin).to eq('file://')
end
end
describe Addressable::URI, "when given the path " +
"'file:/c:\\windows\\My Documents 100%20\\foo.txt'" do
before do
@path = "file:/c:\\windows\\My Documents 100%20\\foo.txt"
end
it "should convert to " +
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("file:///c:/windows/My%20Documents%20100%20/foo.txt")
end
it "should have an origin of 'file://'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.origin).to eq('file://')
end
end
describe Addressable::URI, "when given the path " +
"'file:///c|/windows/My%20Documents%20100%20/foo.txt'" do
before do
@path = "file:///c|/windows/My%20Documents%20100%20/foo.txt"
end
it "should convert to " +
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("file:///c:/windows/My%20Documents%20100%20/foo.txt")
end
it "should have an origin of 'file://'" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.origin).to eq('file://')
end
end
describe Addressable::URI, "when given an http protocol URI" do
before do
@path = "http://example.com/"
end
it "should not do any conversion at all" do
@uri = Addressable::URI.convert_path(@path)
expect(@uri.to_str).to eq("http://example.com/")
end
end
class SuperString
def initialize(string)
@string = string.to_s
end
def to_str
return @string
end
end
describe Addressable::URI, "when parsing a non-String object" do
it "should correctly parse anything with a 'to_str' method" do
Addressable::URI.parse(SuperString.new(42))
end
it "should raise a TypeError for objects than cannot be converted" do
expect(lambda do
Addressable::URI.parse(42)
end).to raise_error(TypeError)
end
it "should correctly parse heuristically anything with a 'to_str' method" do
Addressable::URI.heuristic_parse(SuperString.new(42))
end
it "should raise a TypeError for objects than cannot be converted" do
expect(lambda do
Addressable::URI.heuristic_parse(42)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when form encoding a hash" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.form_encode(
[["&one", "/1"], ["=two", "?2"], [":three", "#3"]]
)).to eq("%26one=%2F1&%3Dtwo=%3F2&%3Athree=%233")
end
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.form_encode(
{"q" => "one two three"}
)).to eq("q=one+two+three")
end
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.form_encode(
{"key" => nil}
)).to eq("key=")
end
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.form_encode(
{"q" => ["one", "two", "three"]}
)).to eq("q=one&q=two&q=three")
end
it "should result in correctly encoded newlines" do
expect(Addressable::URI.form_encode(
{"text" => "one\ntwo\rthree\r\nfour\n\r"}
)).to eq("text=one%0D%0Atwo%0D%0Athree%0D%0Afour%0D%0A%0D%0A")
end
it "should result in a sorted percent encoded sequence" do
expect(Addressable::URI.form_encode(
[["a", "1"], ["dup", "3"], ["dup", "2"]], true
)).to eq("a=1&dup=2&dup=3")
end
end
describe Addressable::URI, "when form encoding a non-Array object" do
it "should raise a TypeError for objects than cannot be converted" do
expect(lambda do
Addressable::URI.form_encode(42)
end).to raise_error(TypeError)
end
end
# See https://tools.ietf.org/html/rfc6749#appendix-B
describe Addressable::URI, "when form encoding the example value from OAuth 2" do
it "should result in correct values" do
expect(Addressable::URI.form_encode(
{"value" => " %&+£€"}
)).to eq("value=+%25%26%2B%C2%A3%E2%82%AC")
end
end
# See https://tools.ietf.org/html/rfc6749#appendix-B
describe Addressable::URI, "when form unencoding the example value from OAuth 2" do
it "should result in correct values" do
expect(Addressable::URI.form_unencode(
"value=+%25%26%2B%C2%A3%E2%82%AC"
)).to eq([["value", " %&+£€"]])
end
end
describe Addressable::URI, "when form unencoding a string" do
it "should result in correct values" do
expect(Addressable::URI.form_unencode(
"%26one=%2F1&%3Dtwo=%3F2&%3Athree=%233"
)).to eq([["&one", "/1"], ["=two", "?2"], [":three", "#3"]])
end
it "should result in correct values" do
expect(Addressable::URI.form_unencode(
"q=one+two+three"
)).to eq([["q", "one two three"]])
end
it "should result in correct values" do
expect(Addressable::URI.form_unencode(
"text=one%0D%0Atwo%0D%0Athree%0D%0Afour%0D%0A%0D%0A"
)).to eq([["text", "one\ntwo\nthree\nfour\n\n"]])
end
it "should result in correct values" do
expect(Addressable::URI.form_unencode(
"a=1&dup=2&dup=3"
)).to eq([["a", "1"], ["dup", "2"], ["dup", "3"]])
end
it "should result in correct values" do
expect(Addressable::URI.form_unencode(
"key"
)).to eq([["key", nil]])
end
it "should result in correct values" do
expect(Addressable::URI.form_unencode("GivenName=Ren%C3%A9")).to eq(
[["GivenName", "René"]]
)
end
end
describe Addressable::URI, "when form unencoding a non-String object" do
it "should correctly parse anything with a 'to_str' method" do
Addressable::URI.form_unencode(SuperString.new(42))
end
it "should raise a TypeError for objects than cannot be converted" do
expect(lambda do
Addressable::URI.form_unencode(42)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when normalizing a non-String object" do
it "should correctly parse anything with a 'to_str' method" do
Addressable::URI.normalize_component(SuperString.new(42))
end
it "should raise a TypeError for objects than cannot be converted" do
expect(lambda do
Addressable::URI.normalize_component(42)
end).to raise_error(TypeError)
end
it "should raise a TypeError for objects than cannot be converted" do
expect(lambda do
Addressable::URI.normalize_component("component", 42)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when normalizing a path with an encoded slash" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.parse("/path%2Fsegment/").normalize.path).to eq(
"/path%2Fsegment/"
)
end
end
describe Addressable::URI, "when normalizing a partially encoded string" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.normalize_component(
"partially % encoded%21"
)).to eq("partially%20%25%20encoded!")
end
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.normalize_component(
"partially %25 encoded!"
)).to eq("partially%20%25%20encoded!")
end
end
describe Addressable::URI, "when normalizing a unicode sequence" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.normalize_component(
"/C%CC%A7"
)).to eq("/%C3%87")
end
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.normalize_component(
"/%C3%87"
)).to eq("/%C3%87")
end
end
describe Addressable::URI, "when normalizing a multibyte string" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.normalize_component("günther")).to eq(
"g%C3%BCnther"
)
end
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.normalize_component("g%C3%BCnther")).to eq(
"g%C3%BCnther"
)
end
end
describe Addressable::URI, "when normalizing a string but leaving some characters encoded" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.normalize_component("%58X%59Y%5AZ", "0-9a-zXY", "Y")).to eq(
"XX%59Y%5A%5A"
)
end
it "should not modify the character class" do
character_class = "0-9a-zXY"
character_class_copy = character_class.dup
Addressable::URI.normalize_component("%58X%59Y%5AZ", character_class, "Y")
expect(character_class).to eq(character_class_copy)
end
end
describe Addressable::URI, "when encoding a string with existing encodings to upcase" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.encode_component("JK%4c", "0-9A-IKM-Za-z%", "L")).to eq("%4AK%4C")
end
end
describe Addressable::URI, "when encoding a multibyte string" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.encode_component("günther")).to eq("g%C3%BCnther")
end
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.encode_component(
"günther", /[^a-zA-Z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\-\.\_\~]/
)).to eq("g%C3%BCnther")
end
end
describe Addressable::URI, "when form encoding a multibyte string" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.form_encode({"GivenName" => "René"})).to eq(
"GivenName=Ren%C3%A9"
)
end
end
describe Addressable::URI, "when encoding a string with ASCII chars 0-15" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.encode_component("one\ntwo")).to eq("one%0Atwo")
end
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.encode_component(
"one\ntwo", /[^a-zA-Z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\-\.\_\~]/
)).to eq("one%0Atwo")
end
end
describe Addressable::URI, "when unencoding a multibyte string" do
it "should result in correct percent encoded sequence" do
expect(Addressable::URI.unencode_component("g%C3%BCnther")).to eq("günther")
end
it "should consistently use UTF-8 internally" do
expect(Addressable::URI.unencode_component("ski=%BA%DAɫ")).to eq("ski=\xBA\xDAɫ")
end
it "should result in correct percent encoded sequence as a URI" do
expect(Addressable::URI.unencode(
"/path?g%C3%BCnther", ::Addressable::URI
)).to eq(Addressable::URI.new(
:path => "/path", :query => "günther"
))
end
end
describe Addressable::URI, "when partially unencoding a string" do
it "should unencode all characters by default" do
expect(Addressable::URI.unencode('%%25~%7e+%2b', String)).to eq('%%~~++')
end
it "should unencode characters not in leave_encoded" do
expect(Addressable::URI.unencode('%%25~%7e+%2b', String, '~')).to eq('%%~%7e++')
end
it "should leave characters in leave_encoded alone" do
expect(Addressable::URI.unencode('%%25~%7e+%2b', String, '%~+')).to eq('%%25~%7e+%2b')
end
end
describe Addressable::URI, "when unencoding a bogus object" do
it "should raise a TypeError" do
expect(lambda do
Addressable::URI.unencode_component(42)
end).to raise_error(TypeError)
end
it "should raise a TypeError" do
expect(lambda do
Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when encoding a bogus object" do
it "should raise a TypeError" do
expect(lambda do
Addressable::URI.encode(Object.new)
end).to raise_error(TypeError)
end
it "should raise a TypeError" do
expect(lambda do
Addressable::URI.normalized_encode(Object.new)
end).to raise_error(TypeError)
end
it "should raise a TypeError" do
expect(lambda do
Addressable::URI.encode_component("günther", Object.new)
end).to raise_error(TypeError)
end
it "should raise a TypeError" do
expect(lambda do
Addressable::URI.encode_component(Object.new)
end).to raise_error(TypeError)
end
end
describe Addressable::URI, "when given the input " +
"'http://example.com/'" do
before do
@input = "http://example.com/"
end
it "should heuristically parse to 'http://example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("http://example.com/")
end
it "should not raise error when frozen" do
expect(lambda do
Addressable::URI.heuristic_parse(@input).freeze.to_s
end).not_to raise_error
end
end
describe Addressable::URI, "when given the input " +
"'https://example.com/'" do
before do
@input = "https://example.com/"
end
it "should heuristically parse to 'https://example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("https://example.com/")
end
end
describe Addressable::URI, "when given the input " +
"'http:example.com/'" do
before do
@input = "http:example.com/"
end
it "should heuristically parse to 'http://example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("http://example.com/")
end
it "should heuristically parse to 'http://example.com/' " +
"even with a scheme hint of 'ftp'" do
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
expect(@uri.to_s).to eq("http://example.com/")
end
end
describe Addressable::URI, "when given the input " +
"'https:example.com/'" do
before do
@input = "https:example.com/"
end
it "should heuristically parse to 'https://example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("https://example.com/")
end
it "should heuristically parse to 'https://example.com/' " +
"even with a scheme hint of 'ftp'" do
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
expect(@uri.to_s).to eq("https://example.com/")
end
end
describe Addressable::URI, "when given the input " +
"'http://example.com/example.com/'" do
before do
@input = "http://example.com/example.com/"
end
it "should heuristically parse to 'http://example.com/example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("http://example.com/example.com/")
end
end
describe Addressable::URI, "when given the input " +
"'http://prefix\\.example.com/'" do
before do
@input = "http://prefix\\.example.com/"
end
it "should heuristically parse to 'http://prefix/.example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.authority).to eq("prefix")
expect(@uri.to_s).to eq("http://prefix/.example.com/")
end
it "should heuristically parse to 'http://prefix/.example.com/' " +
"even with a scheme hint of 'ftp'" do
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
expect(@uri.to_s).to eq("http://prefix/.example.com/")
end
end
describe Addressable::URI, "when given the input " +
"'http://p:\\/'" do
before do
@input = "http://p:\\/"
end
it "should heuristically parse to 'http://p//'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.authority).to eq("p")
expect(@uri.to_s).to eq("http://p//")
end
it "should heuristically parse to 'http://p//' " +
"even with a scheme hint of 'ftp'" do
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
expect(@uri.to_s).to eq("http://p//")
end
end
describe Addressable::URI, "when given the input " +
"'http://p://'" do
before do
@input = "http://p://"
end
it "should heuristically parse to 'http://p//'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.authority).to eq("p")
expect(@uri.to_s).to eq("http://p//")
end
it "should heuristically parse to 'http://p//' " +
"even with a scheme hint of 'ftp'" do
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
expect(@uri.to_s).to eq("http://p//")
end
end
describe Addressable::URI, "when given the input " +
"'http://p://p'" do
before do
@input = "http://p://p"
end
it "should heuristically parse to 'http://p//p'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.authority).to eq("p")
expect(@uri.to_s).to eq("http://p//p")
end
it "should heuristically parse to 'http://p//p' " +
"even with a scheme hint of 'ftp'" do
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
expect(@uri.to_s).to eq("http://p//p")
end
end
describe Addressable::URI, "when given the input " +
"'http://prefix .example.com/'" do
before do
@input = "http://prefix .example.com/"
end
# Justification here being that no browser actually tries to resolve this.
# They all treat this as a web search.
it "should heuristically parse to 'http://prefix%20.example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.authority).to eq("prefix%20.example.com")
expect(@uri.to_s).to eq("http://prefix%20.example.com/")
end
it "should heuristically parse to 'http://prefix%20.example.com/' " +
"even with a scheme hint of 'ftp'" do
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
expect(@uri.to_s).to eq("http://prefix%20.example.com/")
end
end
describe Addressable::URI, "when given the input " +
"' http://www.example.com/ '" do
before do
@input = " http://www.example.com/ "
end
it "should heuristically parse to 'http://prefix%20.example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.scheme).to eq("http")
expect(@uri.path).to eq("/")
expect(@uri.to_s).to eq("http://www.example.com/")
end
end
describe Addressable::URI, "when given the input " +
"'http://prefix%2F.example.com/'" do
before do
@input = "http://prefix%2F.example.com/"
end
it "should heuristically parse to 'http://prefix%2F.example.com/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.authority).to eq("prefix%2F.example.com")
expect(@uri.to_s).to eq("http://prefix%2F.example.com/")
end
it "should heuristically parse to 'http://prefix%2F.example.com/' " +
"even with a scheme hint of 'ftp'" do
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
expect(@uri.to_s).to eq("http://prefix%2F.example.com/")
end
end
describe Addressable::URI, "when given the input " +
"'/path/to/resource'" do
before do
@input = "/path/to/resource"
end
it "should heuristically parse to '/path/to/resource'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("/path/to/resource")
end
end
describe Addressable::URI, "when given the input " +
"'relative/path/to/resource'" do
before do
@input = "relative/path/to/resource"
end
it "should heuristically parse to 'relative/path/to/resource'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("relative/path/to/resource")
end
end
describe Addressable::URI, "when given the input " +
"'example.com'" do
before do
@input = "example.com"
end
it "should heuristically parse to 'http://example.com'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("http://example.com")
end
end
describe Addressable::URI, "when given the input " +
"'example.com' and a scheme hint of 'ftp'" do
before do
@input = "example.com"
@hints = {:scheme => 'ftp'}
end
it "should heuristically parse to 'http://example.com'" do
@uri = Addressable::URI.heuristic_parse(@input, @hints)
expect(@uri.to_s).to eq("ftp://example.com")
end
end
describe Addressable::URI, "when given the input " +
"'example.com:21' and a scheme hint of 'ftp'" do
before do
@input = "example.com:21"
@hints = {:scheme => 'ftp'}
end
it "should heuristically parse to 'http://example.com:21'" do
@uri = Addressable::URI.heuristic_parse(@input, @hints)
expect(@uri.to_s).to eq("ftp://example.com:21")
end
end
describe Addressable::URI, "when given the input " +
"'example.com/path/to/resource'" do
before do
@input = "example.com/path/to/resource"
end
it "should heuristically parse to 'http://example.com/path/to/resource'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("http://example.com/path/to/resource")
end
end
describe Addressable::URI, "when given the input " +
"'http:///example.com'" do
before do
@input = "http:///example.com"
end
it "should heuristically parse to 'http://example.com'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("http://example.com")
end
end
describe Addressable::URI, "when given the input which "\
"start with digits and has specified port" do
before do
@input = "7777.example.org:8089"
end
it "should heuristically parse to 'http://7777.example.org:8089'" do
uri = Addressable::URI.heuristic_parse(@input)
expect(uri.to_s).to eq("http://7777.example.org:8089")
end
end
describe Addressable::URI, "when given the input " +
"'feed:///example.com'" do
before do
@input = "feed:///example.com"
end
it "should heuristically parse to 'feed://example.com'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("feed://example.com")
end
end
describe Addressable::URI, "when given the input " +
"'file://localhost/path/to/resource/'" do
before do
@input = "file://localhost/path/to/resource/"
end
it "should heuristically parse to 'file:///path/to/resource/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("file:///path/to/resource/")
end
end
describe Addressable::URI, "when given the input " +
"'file://path/to/resource/'" do
before do
@input = "file://path/to/resource/"
end
it "should heuristically parse to 'file:///path/to/resource/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("file:///path/to/resource/")
end
end
describe Addressable::URI, "when given the input " +
"'file://///path/to/resource/'" do
before do
@input = "file:///////path/to/resource/"
end
it "should heuristically parse to 'file:////path/to/resource/'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("file:////path/to/resource/")
end
end
describe Addressable::URI, "when given the input " +
"'feed://http://example.com'" do
before do
@input = "feed://http://example.com"
end
it "should heuristically parse to 'feed:http://example.com'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("feed:http://example.com")
end
end
describe Addressable::URI, "when given the input " +
"::URI.parse('http://example.com')" do
before do
@input = ::URI.parse('http://example.com')
end
it "should heuristically parse to 'http://example.com'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("http://example.com")
end
end
describe Addressable::URI, "when given the input: 'user@domain.com'" do
before do
@input = "user@domain.com"
end
context "for heuristic parse" do
it "should remain 'mailto:user@domain.com'" do
uri = Addressable::URI.heuristic_parse("mailto:#{@input}")
expect(uri.to_s).to eq("mailto:user@domain.com")
end
it "should have a scheme of 'mailto'" do
uri = Addressable::URI.heuristic_parse(@input)
expect(uri.to_s).to eq("mailto:user@domain.com")
expect(uri.scheme).to eq("mailto")
end
it "should remain 'acct:user@domain.com'" do
uri = Addressable::URI.heuristic_parse("acct:#{@input}")
expect(uri.to_s).to eq("acct:user@domain.com")
end
context "HTTP" do
before do
@uri = Addressable::URI.heuristic_parse("http://#{@input}/")
end
it "should remain 'http://user@domain.com/'" do
expect(@uri.to_s).to eq("http://user@domain.com/")
end
it "should have the username 'user' for HTTP basic authentication" do
expect(@uri.user).to eq("user")
end
end
end
end
describe Addressable::URI, "when assigning query values" do
before do
@uri = Addressable::URI.new
end
it "should correctly assign {:a => 'a', :b => ['c', 'd', 'e']}" do
@uri.query_values = {:a => "a", :b => ["c", "d", "e"]}
expect(@uri.query).to eq("a=a&b=c&b=d&b=e")
end
it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
expect(lambda do
@uri.query_values = { 'a' => {'b' => ['c'] } }
end).to raise_error(TypeError)
end
it "should raise an error attempting to assign " +
"{:b => '2', :a => {:c => '1'}}" do
expect(lambda do
@uri.query_values = {:b => '2', :a => {:c => '1'}}
end).to raise_error(TypeError)
end
it "should raise an error attempting to assign " +
"{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
"{:e => 'e', :f => 'f'}]}" do
expect(lambda do
@uri.query_values = {
:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
}
end).to raise_error(TypeError)
end
it "should raise an error attempting to assign " +
"{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
"{:e => 'e', :f => 'f'}]}" do
expect(lambda do
@uri.query_values = {
:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
}
end).to raise_error(TypeError)
end
it "should raise an error attempting to assign " +
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
expect(lambda do
@uri.query_values = {
:a => 'a', :b => {:c => true, :d => 'd'}
}
end).to raise_error(TypeError)
end
it "should raise an error attempting to assign " +
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
expect(lambda do
@uri.query_values = {
:a => 'a', :b => {:c => true, :d => 'd'}
}
end).to raise_error(TypeError)
end
it "should correctly assign {:a => 1, :b => 1.5}" do
@uri.query_values = { :a => 1, :b => 1.5 }
expect(@uri.query).to eq("a=1&b=1.5")
end
it "should raise an error attempting to assign " +
"{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
expect(lambda do
@uri.query_values = {
:z => 1,
:f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
:a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
}
end).to raise_error(TypeError)
end
it "should correctly assign {}" do
@uri.query_values = {}
expect(@uri.query).to eq('')
end
it "should correctly assign nil" do
@uri.query_values = nil
expect(@uri.query).to eq(nil)
end
it "should correctly sort {'ab' => 'c', :ab => 'a', :a => 'x'}" do
@uri.query_values = {'ab' => 'c', :ab => 'a', :a => 'x'}
expect(@uri.query).to eq("a=x&ab=a&ab=c")
end
it "should correctly assign " +
"[['b', 'c'], ['b', 'a'], ['a', 'a']]" do
# Order can be guaranteed in this format, so preserve it.
@uri.query_values = [['b', 'c'], ['b', 'a'], ['a', 'a']]
expect(@uri.query).to eq("b=c&b=a&a=a")
end
it "should preserve query string order" do
query_string = (('a'..'z').to_a.reverse.map { |e| "#{e}=#{e}" }).join("&")
@uri.query = query_string
original_uri = @uri.to_s
@uri.query_values = @uri.query_values(Array)
expect(@uri.to_s).to eq(original_uri)
end
describe 'when a hash with mixed types is assigned to query_values' do
it 'should not raise an error' do
skip 'Issue #94'
expect { subject.query_values = { "page" => "1", :page => 2 } }.to_not raise_error
end
end
end
describe Addressable::URI, "when assigning path values" do
before do
@uri = Addressable::URI.new
end
it "should correctly assign paths containing colons" do
@uri.path = "acct:bob@sporkmonger.com"
expect(@uri.path).to eq("acct:bob@sporkmonger.com")
expect(@uri.normalize.to_str).to eq("acct%2Fbob@sporkmonger.com")
expect(lambda { @uri.to_s }).to raise_error(
Addressable::URI::InvalidURIError
)
end
it "should correctly assign paths containing colons" do
@uri.path = "/acct:bob@sporkmonger.com"
@uri.authority = "example.com"
expect(@uri.normalize.to_str).to eq("//example.com/acct:bob@sporkmonger.com")
end
it "should correctly assign paths containing colons" do
@uri.path = "acct:bob@sporkmonger.com"
@uri.scheme = "something"
expect(@uri.normalize.to_str).to eq("something:acct:bob@sporkmonger.com")
end
it "should not allow relative paths to be assigned on absolute URIs" do
expect(lambda do
@uri.scheme = "http"
@uri.host = "example.com"
@uri.path = "acct:bob@sporkmonger.com"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should not allow relative paths to be assigned on absolute URIs" do
expect(lambda do
@uri.path = "acct:bob@sporkmonger.com"
@uri.scheme = "http"
@uri.host = "example.com"
end).to raise_error(Addressable::URI::InvalidURIError)
end
it "should not allow relative paths to be assigned on absolute URIs" do
expect(lambda do
@uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
@uri.scheme = "urn"
end).not_to raise_error
end
end
describe Addressable::URI, "when initializing a subclass of Addressable::URI" do
before do
@uri = Class.new(Addressable::URI).new
end
it "should have the same class after being parsed" do
expect(@uri.class).to eq(Addressable::URI.parse(@uri).class)
end
it "should have the same class as its duplicate" do
expect(@uri.class).to eq(@uri.dup.class)
end
it "should have the same class after being normalized" do
expect(@uri.class).to eq(@uri.normalize.class)
end
it "should have the same class after being merged" do
expect(@uri.class).to eq(@uri.merge(:path => 'path').class)
end
it "should have the same class after being joined" do
expect(@uri.class).to eq(@uri.join('path').class)
end
end
addressable-2.7.0/spec/addressable/template_spec.rb 0000644 0000041 0000041 00000132306 13534474053 022413 0 ustar www-data www-data # frozen_string_literal: true
# coding: utf-8
# Copyright (C) Bob Aman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require "spec_helper"
require "bigdecimal"
require "addressable/template"
shared_examples_for 'expands' do |tests|
tests.each do |template, expansion|
exp = expansion.is_a?(Array) ? expansion.first : expansion
it "#{template} to #{exp}" do
tmpl = Addressable::Template.new(template).expand(subject)
if expansion.is_a?(Array)
expect(expansion.any?{|i| i == tmpl.to_str}).to be true
else
expect(tmpl.to_str).to eq(expansion)
end
end
end
end
describe "eql?" do
let(:template) { Addressable::Template.new('https://www.example.com/{foo}') }
it 'is equal when the pattern matches' do
other_template = Addressable::Template.new('https://www.example.com/{foo}')
expect(template).to be_eql(other_template)
expect(other_template).to be_eql(template)
end
it 'is not equal when the pattern differs' do
other_template = Addressable::Template.new('https://www.example.com/{bar}')
expect(template).to_not be_eql(other_template)
expect(other_template).to_not be_eql(template)
end
it 'is not equal to non-templates' do
uri = 'https://www.example.com/foo/bar'
addressable_template = Addressable::Template.new uri
addressable_uri = Addressable::URI.parse uri
expect(addressable_template).to_not be_eql(addressable_uri)
expect(addressable_uri).to_not be_eql(addressable_template)
end
end
describe "==" do
let(:template) { Addressable::Template.new('https://www.example.com/{foo}') }
it 'is equal when the pattern matches' do
other_template = Addressable::Template.new('https://www.example.com/{foo}')
expect(template).to eq other_template
expect(other_template).to eq template
end
it 'is not equal when the pattern differs' do
other_template = Addressable::Template.new('https://www.example.com/{bar}')
expect(template).not_to eq other_template
expect(other_template).not_to eq template
end
it 'is not equal to non-templates' do
uri = 'https://www.example.com/foo/bar'
addressable_template = Addressable::Template.new uri
addressable_uri = Addressable::URI.parse uri
expect(addressable_template).not_to eq addressable_uri
expect(addressable_uri).not_to eq addressable_template
end
end
describe "Type conversion" do
subject {
{
:var => true,
:hello => 1234,
:nothing => nil,
:sym => :symbolic,
:decimal => BigDecimal('1')
}
}
it_behaves_like 'expands', {
'{var}' => 'true',
'{hello}' => '1234',
'{nothing}' => '',
'{sym}' => 'symbolic',
'{decimal}' => RUBY_VERSION < '2.4.0' ? '0.1E1' : '0.1e1'
}
end
describe "Level 1:" do
subject {
{:var => "value", :hello => "Hello World!"}
}
it_behaves_like 'expands', {
'{var}' => 'value',
'{hello}' => 'Hello%20World%21'
}
end
describe "Level 2" do
subject {
{
:var => "value",
:hello => "Hello World!",
:path => "/foo/bar"
}
}
context "Operator +:" do
it_behaves_like 'expands', {
'{+var}' => 'value',
'{+hello}' => 'Hello%20World!',
'{+path}/here' => '/foo/bar/here',
'here?ref={+path}' => 'here?ref=/foo/bar'
}
end
context "Operator #:" do
it_behaves_like 'expands', {
'X{#var}' => 'X#value',
'X{#hello}' => 'X#Hello%20World!'
}
end
end
describe "Level 3" do
subject {
{
:var => "value",
:hello => "Hello World!",
:empty => "",
:path => "/foo/bar",
:x => "1024",
:y => "768"
}
}
context "Operator nil (multiple vars):" do
it_behaves_like 'expands', {
'map?{x,y}' => 'map?1024,768',
'{x,hello,y}' => '1024,Hello%20World%21,768'
}
end
context "Operator + (multiple vars):" do
it_behaves_like 'expands', {
'{+x,hello,y}' => '1024,Hello%20World!,768',
'{+path,x}/here' => '/foo/bar,1024/here'
}
end
context "Operator # (multiple vars):" do
it_behaves_like 'expands', {
'{#x,hello,y}' => '#1024,Hello%20World!,768',
'{#path,x}/here' => '#/foo/bar,1024/here'
}
end
context "Operator ." do
it_behaves_like 'expands', {
'X{.var}' => 'X.value',
'X{.x,y}' => 'X.1024.768'
}
end
context "Operator /" do
it_behaves_like 'expands', {
'{/var}' => '/value',
'{/var,x}/here' => '/value/1024/here'
}
end
context "Operator ;" do
it_behaves_like 'expands', {
'{;x,y}' => ';x=1024;y=768',
'{;x,y,empty}' => ';x=1024;y=768;empty'
}
end
context "Operator ?" do
it_behaves_like 'expands', {
'{?x,y}' => '?x=1024&y=768',
'{?x,y,empty}' => '?x=1024&y=768&empty='
}
end
context "Operator &" do
it_behaves_like 'expands', {
'?fixed=yes{&x}' => '?fixed=yes&x=1024',
'{&x,y,empty}' => '&x=1024&y=768&empty='
}
end
end
describe "Level 4" do
subject {
{
:var => "value",
:hello => "Hello World!",
:path => "/foo/bar",
:semi => ";",
:list => %w(red green blue),
:keys => {"semi" => ';', "dot" => '.', "comma" => ','}
}
}
context "Expansion with value modifiers" do
it_behaves_like 'expands', {
'{var:3}' => 'val',
'{var:30}' => 'value',
'{list}' => 'red,green,blue',
'{list*}' => 'red,green,blue',
'{keys}' => [
'semi,%3B,dot,.,comma,%2C',
'dot,.,semi,%3B,comma,%2C',
'comma,%2C,semi,%3B,dot,.',
'semi,%3B,comma,%2C,dot,.',
'dot,.,comma,%2C,semi,%3B',
'comma,%2C,dot,.,semi,%3B'
],
'{keys*}' => [
'semi=%3B,dot=.,comma=%2C',
'dot=.,semi=%3B,comma=%2C',
'comma=%2C,semi=%3B,dot=.',
'semi=%3B,comma=%2C,dot=.',
'dot=.,comma=%2C,semi=%3B',
'comma=%2C,dot=.,semi=%3B'
]
}
end
context "Operator + with value modifiers" do
it_behaves_like 'expands', {
'{+path:6}/here' => '/foo/b/here',
'{+list}' => 'red,green,blue',
'{+list*}' => 'red,green,blue',
'{+keys}' => [
'semi,;,dot,.,comma,,',
'dot,.,semi,;,comma,,',
'comma,,,semi,;,dot,.',
'semi,;,comma,,,dot,.',
'dot,.,comma,,,semi,;',
'comma,,,dot,.,semi,;'
],
'{+keys*}' => [
'semi=;,dot=.,comma=,',
'dot=.,semi=;,comma=,',
'comma=,,semi=;,dot=.',
'semi=;,comma=,,dot=.',
'dot=.,comma=,,semi=;',
'comma=,,dot=.,semi=;'
]
}
end
context "Operator # with value modifiers" do
it_behaves_like 'expands', {
'{#path:6}/here' => '#/foo/b/here',
'{#list}' => '#red,green,blue',
'{#list*}' => '#red,green,blue',
'{#keys}' => [
'#semi,;,dot,.,comma,,',
'#dot,.,semi,;,comma,,',
'#comma,,,semi,;,dot,.',
'#semi,;,comma,,,dot,.',
'#dot,.,comma,,,semi,;',
'#comma,,,dot,.,semi,;'
],
'{#keys*}' => [
'#semi=;,dot=.,comma=,',
'#dot=.,semi=;,comma=,',
'#comma=,,semi=;,dot=.',
'#semi=;,comma=,,dot=.',
'#dot=.,comma=,,semi=;',
'#comma=,,dot=.,semi=;'
]
}
end
context "Operator . with value modifiers" do
it_behaves_like 'expands', {
'X{.var:3}' => 'X.val',
'X{.list}' => 'X.red,green,blue',
'X{.list*}' => 'X.red.green.blue',
'X{.keys}' => [
'X.semi,%3B,dot,.,comma,%2C',
'X.dot,.,semi,%3B,comma,%2C',
'X.comma,%2C,semi,%3B,dot,.',
'X.semi,%3B,comma,%2C,dot,.',
'X.dot,.,comma,%2C,semi,%3B',
'X.comma,%2C,dot,.,semi,%3B'
],
'X{.keys*}' => [
'X.semi=%3B.dot=..comma=%2C',
'X.dot=..semi=%3B.comma=%2C',
'X.comma=%2C.semi=%3B.dot=.',
'X.semi=%3B.comma=%2C.dot=.',
'X.dot=..comma=%2C.semi=%3B',
'X.comma=%2C.dot=..semi=%3B'
]
}
end
context "Operator / with value modifiers" do
it_behaves_like 'expands', {
'{/var:1,var}' => '/v/value',
'{/list}' => '/red,green,blue',
'{/list*}' => '/red/green/blue',
'{/list*,path:4}' => '/red/green/blue/%2Ffoo',
'{/keys}' => [
'/semi,%3B,dot,.,comma,%2C',
'/dot,.,semi,%3B,comma,%2C',
'/comma,%2C,semi,%3B,dot,.',
'/semi,%3B,comma,%2C,dot,.',
'/dot,.,comma,%2C,semi,%3B',
'/comma,%2C,dot,.,semi,%3B'
],
'{/keys*}' => [
'/semi=%3B/dot=./comma=%2C',
'/dot=./semi=%3B/comma=%2C',
'/comma=%2C/semi=%3B/dot=.',
'/semi=%3B/comma=%2C/dot=.',
'/dot=./comma=%2C/semi=%3B',
'/comma=%2C/dot=./semi=%3B'
]
}
end
context "Operator ; with value modifiers" do
it_behaves_like 'expands', {
'{;hello:5}' => ';hello=Hello',
'{;list}' => ';list=red,green,blue',
'{;list*}' => ';list=red;list=green;list=blue',
'{;keys}' => [
';keys=semi,%3B,dot,.,comma,%2C',
';keys=dot,.,semi,%3B,comma,%2C',
';keys=comma,%2C,semi,%3B,dot,.',
';keys=semi,%3B,comma,%2C,dot,.',
';keys=dot,.,comma,%2C,semi,%3B',
';keys=comma,%2C,dot,.,semi,%3B'
],
'{;keys*}' => [
';semi=%3B;dot=.;comma=%2C',
';dot=.;semi=%3B;comma=%2C',
';comma=%2C;semi=%3B;dot=.',
';semi=%3B;comma=%2C;dot=.',
';dot=.;comma=%2C;semi=%3B',
';comma=%2C;dot=.;semi=%3B'
]
}
end
context "Operator ? with value modifiers" do
it_behaves_like 'expands', {
'{?var:3}' => '?var=val',
'{?list}' => '?list=red,green,blue',
'{?list*}' => '?list=red&list=green&list=blue',
'{?keys}' => [
'?keys=semi,%3B,dot,.,comma,%2C',
'?keys=dot,.,semi,%3B,comma,%2C',
'?keys=comma,%2C,semi,%3B,dot,.',
'?keys=semi,%3B,comma,%2C,dot,.',
'?keys=dot,.,comma,%2C,semi,%3B',
'?keys=comma,%2C,dot,.,semi,%3B'
],
'{?keys*}' => [
'?semi=%3B&dot=.&comma=%2C',
'?dot=.&semi=%3B&comma=%2C',
'?comma=%2C&semi=%3B&dot=.',
'?semi=%3B&comma=%2C&dot=.',
'?dot=.&comma=%2C&semi=%3B',
'?comma=%2C&dot=.&semi=%3B'
]
}
end
context "Operator & with value modifiers" do
it_behaves_like 'expands', {
'{&var:3}' => '&var=val',
'{&list}' => '&list=red,green,blue',
'{&list*}' => '&list=red&list=green&list=blue',
'{&keys}' => [
'&keys=semi,%3B,dot,.,comma,%2C',
'&keys=dot,.,semi,%3B,comma,%2C',
'&keys=comma,%2C,semi,%3B,dot,.',
'&keys=semi,%3B,comma,%2C,dot,.',
'&keys=dot,.,comma,%2C,semi,%3B',
'&keys=comma,%2C,dot,.,semi,%3B'
],
'{&keys*}' => [
'&semi=%3B&dot=.&comma=%2C',
'&dot=.&semi=%3B&comma=%2C',
'&comma=%2C&semi=%3B&dot=.',
'&semi=%3B&comma=%2C&dot=.',
'&dot=.&comma=%2C&semi=%3B',
'&comma=%2C&dot=.&semi=%3B'
]
}
end
end
describe "Modifiers" do
subject {
{
:var => "value",
:semi => ";",
:year => %w(1965 2000 2012),
:dom => %w(example com)
}
}
context "length" do
it_behaves_like 'expands', {
'{var:3}' => 'val',
'{var:30}' => 'value',
'{var}' => 'value',
'{semi}' => '%3B',
'{semi:2}' => '%3B'
}
end
context "explode" do
it_behaves_like 'expands', {
'find{?year*}' => 'find?year=1965&year=2000&year=2012',
'www{.dom*}' => 'www.example.com',
}
end
end
describe "Expansion" do
subject {
{
:count => ["one", "two", "three"],
:dom => ["example", "com"],
:dub => "me/too",
:hello => "Hello World!",
:half => "50%",
:var => "value",
:who => "fred",
:base => "http://example.com/home/",
:path => "/foo/bar",
:list => ["red", "green", "blue"],
:keys => {"semi" => ";","dot" => ".","comma" => ","},
:v => "6",
:x => "1024",
:y => "768",
:empty => "",
:empty_keys => {},
:undef => nil
}
}
context "concatenation" do
it_behaves_like 'expands', {
'{count}' => 'one,two,three',
'{count*}' => 'one,two,three',
'{/count}' => '/one,two,three',
'{/count*}' => '/one/two/three',
'{;count}' => ';count=one,two,three',
'{;count*}' => ';count=one;count=two;count=three',
'{?count}' => '?count=one,two,three',
'{?count*}' => '?count=one&count=two&count=three',
'{&count*}' => '&count=one&count=two&count=three'
}
end
context "simple expansion" do
it_behaves_like 'expands', {
'{var}' => 'value',
'{hello}' => 'Hello%20World%21',
'{half}' => '50%25',
'O{empty}X' => 'OX',
'O{undef}X' => 'OX',
'{x,y}' => '1024,768',
'{x,hello,y}' => '1024,Hello%20World%21,768',
'?{x,empty}' => '?1024,',
'?{x,undef}' => '?1024',
'?{undef,y}' => '?768',
'{var:3}' => 'val',
'{var:30}' => 'value',
'{list}' => 'red,green,blue',
'{list*}' => 'red,green,blue',
'{keys}' => [
'semi,%3B,dot,.,comma,%2C',
'dot,.,semi,%3B,comma,%2C',
'comma,%2C,semi,%3B,dot,.',
'semi,%3B,comma,%2C,dot,.',
'dot,.,comma,%2C,semi,%3B',
'comma,%2C,dot,.,semi,%3B'
],
'{keys*}' => [
'semi=%3B,dot=.,comma=%2C',
'dot=.,semi=%3B,comma=%2C',
'comma=%2C,semi=%3B,dot=.',
'semi=%3B,comma=%2C,dot=.',
'dot=.,comma=%2C,semi=%3B',
'comma=%2C,dot=.,semi=%3B'
]
}
end
context "reserved expansion (+)" do
it_behaves_like 'expands', {
'{+var}' => 'value',
'{+hello}' => 'Hello%20World!',
'{+half}' => '50%25',
'{base}index' => 'http%3A%2F%2Fexample.com%2Fhome%2Findex',
'{+base}index' => 'http://example.com/home/index',
'O{+empty}X' => 'OX',
'O{+undef}X' => 'OX',
'{+path}/here' => '/foo/bar/here',
'here?ref={+path}' => 'here?ref=/foo/bar',
'up{+path}{var}/here' => 'up/foo/barvalue/here',
'{+x,hello,y}' => '1024,Hello%20World!,768',
'{+path,x}/here' => '/foo/bar,1024/here',
'{+path:6}/here' => '/foo/b/here',
'{+list}' => 'red,green,blue',
'{+list*}' => 'red,green,blue',
'{+keys}' => [
'semi,;,dot,.,comma,,',
'dot,.,semi,;,comma,,',
'comma,,,semi,;,dot,.',
'semi,;,comma,,,dot,.',
'dot,.,comma,,,semi,;',
'comma,,,dot,.,semi,;'
],
'{+keys*}' => [
'semi=;,dot=.,comma=,',
'dot=.,semi=;,comma=,',
'comma=,,semi=;,dot=.',
'semi=;,comma=,,dot=.',
'dot=.,comma=,,semi=;',
'comma=,,dot=.,semi=;'
]
}
end
context "fragment expansion (#)" do
it_behaves_like 'expands', {
'{#var}' => '#value',
'{#hello}' => '#Hello%20World!',
'{#half}' => '#50%25',
'foo{#empty}' => 'foo#',
'foo{#undef}' => 'foo',
'{#x,hello,y}' => '#1024,Hello%20World!,768',
'{#path,x}/here' => '#/foo/bar,1024/here',
'{#path:6}/here' => '#/foo/b/here',
'{#list}' => '#red,green,blue',
'{#list*}' => '#red,green,blue',
'{#keys}' => [
'#semi,;,dot,.,comma,,',
'#dot,.,semi,;,comma,,',
'#comma,,,semi,;,dot,.',
'#semi,;,comma,,,dot,.',
'#dot,.,comma,,,semi,;',
'#comma,,,dot,.,semi,;'
],
'{#keys*}' => [
'#semi=;,dot=.,comma=,',
'#dot=.,semi=;,comma=,',
'#comma=,,semi=;,dot=.',
'#semi=;,comma=,,dot=.',
'#dot=.,comma=,,semi=;',
'#comma=,,dot=.,semi=;'
]
}
end
context "label expansion (.)" do
it_behaves_like 'expands', {
'{.who}' => '.fred',
'{.who,who}' => '.fred.fred',
'{.half,who}' => '.50%25.fred',
'www{.dom*}' => 'www.example.com',
'X{.var}' => 'X.value',
'X{.empty}' => 'X.',
'X{.undef}' => 'X',
'X{.var:3}' => 'X.val',
'X{.list}' => 'X.red,green,blue',
'X{.list*}' => 'X.red.green.blue',
'X{.keys}' => [
'X.semi,%3B,dot,.,comma,%2C',
'X.dot,.,semi,%3B,comma,%2C',
'X.comma,%2C,semi,%3B,dot,.',
'X.semi,%3B,comma,%2C,dot,.',
'X.dot,.,comma,%2C,semi,%3B',
'X.comma,%2C,dot,.,semi,%3B'
],
'X{.keys*}' => [
'X.semi=%3B.dot=..comma=%2C',
'X.dot=..semi=%3B.comma=%2C',
'X.comma=%2C.semi=%3B.dot=.',
'X.semi=%3B.comma=%2C.dot=.',
'X.dot=..comma=%2C.semi=%3B',
'X.comma=%2C.dot=..semi=%3B'
],
'X{.empty_keys}' => 'X',
'X{.empty_keys*}' => 'X'
}
end
context "path expansion (/)" do
it_behaves_like 'expands', {
'{/who}' => '/fred',
'{/who,who}' => '/fred/fred',
'{/half,who}' => '/50%25/fred',
'{/who,dub}' => '/fred/me%2Ftoo',
'{/var}' => '/value',
'{/var,empty}' => '/value/',
'{/var,undef}' => '/value',
'{/var,x}/here' => '/value/1024/here',
'{/var:1,var}' => '/v/value',
'{/list}' => '/red,green,blue',
'{/list*}' => '/red/green/blue',
'{/list*,path:4}' => '/red/green/blue/%2Ffoo',
'{/keys}' => [
'/semi,%3B,dot,.,comma,%2C',
'/dot,.,semi,%3B,comma,%2C',
'/comma,%2C,semi,%3B,dot,.',
'/semi,%3B,comma,%2C,dot,.',
'/dot,.,comma,%2C,semi,%3B',
'/comma,%2C,dot,.,semi,%3B'
],
'{/keys*}' => [
'/semi=%3B/dot=./comma=%2C',
'/dot=./semi=%3B/comma=%2C',
'/comma=%2C/semi=%3B/dot=.',
'/semi=%3B/comma=%2C/dot=.',
'/dot=./comma=%2C/semi=%3B',
'/comma=%2C/dot=./semi=%3B'
]
}
end
context "path-style expansion (;)" do
it_behaves_like 'expands', {
'{;who}' => ';who=fred',
'{;half}' => ';half=50%25',
'{;empty}' => ';empty',
'{;v,empty,who}' => ';v=6;empty;who=fred',
'{;v,bar,who}' => ';v=6;who=fred',
'{;x,y}' => ';x=1024;y=768',
'{;x,y,empty}' => ';x=1024;y=768;empty',
'{;x,y,undef}' => ';x=1024;y=768',
'{;hello:5}' => ';hello=Hello',
'{;list}' => ';list=red,green,blue',
'{;list*}' => ';list=red;list=green;list=blue',
'{;keys}' => [
';keys=semi,%3B,dot,.,comma,%2C',
';keys=dot,.,semi,%3B,comma,%2C',
';keys=comma,%2C,semi,%3B,dot,.',
';keys=semi,%3B,comma,%2C,dot,.',
';keys=dot,.,comma,%2C,semi,%3B',
';keys=comma,%2C,dot,.,semi,%3B'
],
'{;keys*}' => [
';semi=%3B;dot=.;comma=%2C',
';dot=.;semi=%3B;comma=%2C',
';comma=%2C;semi=%3B;dot=.',
';semi=%3B;comma=%2C;dot=.',
';dot=.;comma=%2C;semi=%3B',
';comma=%2C;dot=.;semi=%3B'
]
}
end
context "form query expansion (?)" do
it_behaves_like 'expands', {
'{?who}' => '?who=fred',
'{?half}' => '?half=50%25',
'{?x,y}' => '?x=1024&y=768',
'{?x,y,empty}' => '?x=1024&y=768&empty=',
'{?x,y,undef}' => '?x=1024&y=768',
'{?var:3}' => '?var=val',
'{?list}' => '?list=red,green,blue',
'{?list*}' => '?list=red&list=green&list=blue',
'{?keys}' => [
'?keys=semi,%3B,dot,.,comma,%2C',
'?keys=dot,.,semi,%3B,comma,%2C',
'?keys=comma,%2C,semi,%3B,dot,.',
'?keys=semi,%3B,comma,%2C,dot,.',
'?keys=dot,.,comma,%2C,semi,%3B',
'?keys=comma,%2C,dot,.,semi,%3B'
],
'{?keys*}' => [
'?semi=%3B&dot=.&comma=%2C',
'?dot=.&semi=%3B&comma=%2C',
'?comma=%2C&semi=%3B&dot=.',
'?semi=%3B&comma=%2C&dot=.',
'?dot=.&comma=%2C&semi=%3B',
'?comma=%2C&dot=.&semi=%3B'
]
}
end
context "form query expansion (&)" do
it_behaves_like 'expands', {
'{&who}' => '&who=fred',
'{&half}' => '&half=50%25',
'?fixed=yes{&x}' => '?fixed=yes&x=1024',
'{&x,y,empty}' => '&x=1024&y=768&empty=',
'{&x,y,undef}' => '&x=1024&y=768',
'{&var:3}' => '&var=val',
'{&list}' => '&list=red,green,blue',
'{&list*}' => '&list=red&list=green&list=blue',
'{&keys}' => [
'&keys=semi,%3B,dot,.,comma,%2C',
'&keys=dot,.,semi,%3B,comma,%2C',
'&keys=comma,%2C,semi,%3B,dot,.',
'&keys=semi,%3B,comma,%2C,dot,.',
'&keys=dot,.,comma,%2C,semi,%3B',
'&keys=comma,%2C,dot,.,semi,%3B'
],
'{&keys*}' => [
'&semi=%3B&dot=.&comma=%2C',
'&dot=.&semi=%3B&comma=%2C',
'&comma=%2C&semi=%3B&dot=.',
'&semi=%3B&comma=%2C&dot=.',
'&dot=.&comma=%2C&semi=%3B',
'&comma=%2C&dot=.&semi=%3B'
]
}
end
context "non-string key in match data" do
subject {Addressable::Template.new("http://example.com/{one}")}
it "raises TypeError" do
expect { subject.expand(Object.new => "1") }.to raise_error TypeError
end
end
end
class ExampleTwoProcessor
def self.restore(name, value)
return value.gsub(/-/, " ") if name == "query"
return value
end
def self.match(name)
return ".*?" if name == "first"
return ".*"
end
def self.validate(name, value)
return !!(value =~ /^[\w ]+$/) if name == "query"
return true
end
def self.transform(name, value)
return value.gsub(/ /, "+") if name == "query"
return value
end
end
class DumbProcessor
def self.match(name)
return ".*?" if name == "first"
end
end
describe Addressable::Template do
describe 'initialize' do
context 'with a non-string' do
it 'raises a TypeError' do
expect { Addressable::Template.new(nil) }.to raise_error(TypeError)
end
end
end
describe 'freeze' do
subject { Addressable::Template.new("http://example.com/{first}/{+second}/") }
it 'freezes the template' do
expect(subject.freeze).to be_frozen
end
end
describe "Matching" do
let(:uri){
Addressable::URI.parse(
"http://example.com/search/an-example-search-query/"
)
}
let(:uri2){
Addressable::URI.parse("http://example.com/a/b/c/")
}
let(:uri3){
Addressable::URI.parse("http://example.com/;a=1;b=2;c=3;first=foo")
}
let(:uri4){
Addressable::URI.parse("http://example.com/?a=1&b=2&c=3&first=foo")
}
let(:uri5){
"http://example.com/foo"
}
context "first uri with ExampleTwoProcessor" do
subject {
Addressable::Template.new(
"http://example.com/search/{query}/"
).match(uri, ExampleTwoProcessor)
}
its(:variables){ should == ["query"] }
its(:captures){ should == ["an example search query"] }
end
context "second uri with ExampleTwoProcessor" do
subject {
Addressable::Template.new(
"http://example.com/{first}/{+second}/"
).match(uri2, ExampleTwoProcessor)
}
its(:variables){ should == ["first", "second"] }
its(:captures){ should == ["a", "b/c"] }
end
context "second uri with DumbProcessor" do
subject {
Addressable::Template.new(
"http://example.com/{first}/{+second}/"
).match(uri2, DumbProcessor)
}
its(:variables){ should == ["first", "second"] }
its(:captures){ should == ["a", "b/c"] }
end
context "second uri" do
subject {
Addressable::Template.new(
"http://example.com/{first}{/second*}/"
).match(uri2)
}
its(:variables){ should == ["first", "second"] }
its(:captures){ should == ["a", ["b","c"]] }
end
context "third uri" do
subject {
Addressable::Template.new(
"http://example.com/{;hash*,first}"
).match(uri3)
}
its(:variables){ should == ["hash", "first"] }
its(:captures){ should == [
{"a" => "1", "b" => "2", "c" => "3", "first" => "foo"}, nil] }
end
# Note that this expansion is impossible to revert deterministically - the
# * operator means first could have been a key of hash or a separate key.
# Semantically, a separate key is more likely, but both are possible.
context "fourth uri" do
subject {
Addressable::Template.new(
"http://example.com/{?hash*,first}"
).match(uri4)
}
its(:variables){ should == ["hash", "first"] }
its(:captures){ should == [
{"a" => "1", "b" => "2", "c" => "3", "first"=> "foo"}, nil] }
end
context "fifth uri" do
subject {
Addressable::Template.new(
"http://example.com/{path}{?hash*,first}"
).match(uri5)
}
its(:variables){ should == ["path", "hash", "first"] }
its(:captures){ should == ["foo", nil, nil] }
end
end
describe 'match' do
subject { Addressable::Template.new('http://example.com/first/second/') }
context 'when the URI is the same as the template' do
it 'returns the match data itself with an empty mapping' do
uri = Addressable::URI.parse('http://example.com/first/second/')
match_data = subject.match(uri)
expect(match_data).to be_an Addressable::Template::MatchData
expect(match_data.uri).to eq(uri)
expect(match_data.template).to eq(subject)
expect(match_data.mapping).to be_empty
expect(match_data.inspect).to be_an String
end
end
end
describe "extract" do
let(:template) {
Addressable::Template.new(
"http://{host}{/segments*}/{?one,two,bogus}{#fragment}"
)
}
let(:uri){ "http://example.com/a/b/c/?one=1&two=2#foo" }
let(:uri2){ "http://example.com/a/b/c/#foo" }
it "should be able to extract with queries" do
expect(template.extract(uri)).to eq({
"host" => "example.com",
"segments" => %w(a b c),
"one" => "1",
"bogus" => nil,
"two" => "2",
"fragment" => "foo"
})
end
it "should be able to extract without queries" do
expect(template.extract(uri2)).to eq({
"host" => "example.com",
"segments" => %w(a b c),
"one" => nil,
"bogus" => nil,
"two" => nil,
"fragment" => "foo"
})
end
context "issue #137" do
subject { Addressable::Template.new('/path{?page,per_page}') }
it "can match empty" do
data = subject.extract("/path")
expect(data["page"]).to eq(nil)
expect(data["per_page"]).to eq(nil)
expect(data.keys.sort).to eq(['page', 'per_page'])
end
it "can match first var" do
data = subject.extract("/path?page=1")
expect(data["page"]).to eq("1")
expect(data["per_page"]).to eq(nil)
expect(data.keys.sort).to eq(['page', 'per_page'])
end
it "can match second var" do
data = subject.extract("/path?per_page=1")
expect(data["page"]).to eq(nil)
expect(data["per_page"]).to eq("1")
expect(data.keys.sort).to eq(['page', 'per_page'])
end
it "can match both vars" do
data = subject.extract("/path?page=2&per_page=1")
expect(data["page"]).to eq("2")
expect(data["per_page"]).to eq("1")
expect(data.keys.sort).to eq(['page', 'per_page'])
end
end
end
describe "Partial expand with symbols" do
context "partial_expand with two simple values" do
subject {
Addressable::Template.new("http://example.com/{one}/{two}/")
}
it "builds a new pattern" do
expect(subject.partial_expand(:one => "1").pattern).to eq(
"http://example.com/1/{two}/"
)
end
end
context "partial_expand query with missing param in middle" do
subject {
Addressable::Template.new("http://example.com/{?one,two,three}/")
}
it "builds a new pattern" do
expect(subject.partial_expand(:one => "1", :three => "3").pattern).to eq(
"http://example.com/?one=1{&two}&three=3/"
)
end
end
context "partial_expand form style query with missing param at beginning" do
subject {
Addressable::Template.new("http://example.com/{?one,two}/")
}
it "builds a new pattern" do
expect(subject.partial_expand(:two => "2").pattern).to eq(
"http://example.com/?two=2{&one}/"
)
end
end
context "issue #307 - partial_expand form query with nil params" do
subject do
Addressable::Template.new("http://example.com/{?one,two,three}/")
end
it "builds a new pattern with two=nil" do
expect(subject.partial_expand(two: nil).pattern).to eq(
"http://example.com/{?one}{&three}/"
)
end
it "builds a new pattern with one=nil and two=nil" do
expect(subject.partial_expand(one: nil, two: nil).pattern).to eq(
"http://example.com/{?three}/"
)
end
it "builds a new pattern with one=1 and two=nil" do
expect(subject.partial_expand(one: 1, two: nil).pattern).to eq(
"http://example.com/?one=1{&three}/"
)
end
it "builds a new pattern with one=nil and two=2" do
expect(subject.partial_expand(one: nil, two: 2).pattern).to eq(
"http://example.com/?two=2{&three}/"
)
end
it "builds a new pattern with one=nil" do
expect(subject.partial_expand(one: nil).pattern).to eq(
"http://example.com/{?two}{&three}/"
)
end
end
context "partial_expand with query string" do
subject {
Addressable::Template.new("http://example.com/{?two,one}/")
}
it "builds a new pattern" do
expect(subject.partial_expand(:one => "1").pattern).to eq(
"http://example.com/?one=1{&two}/"
)
end
end
context "partial_expand with path operator" do
subject {
Addressable::Template.new("http://example.com{/one,two}/")
}
it "builds a new pattern" do
expect(subject.partial_expand(:one => "1").pattern).to eq(
"http://example.com/1{/two}/"
)
end
end
context "partial expand with unicode values" do
subject do
Addressable::Template.new("http://example.com/{resource}/{query}/")
end
it "normalizes unicode by default" do
template = subject.partial_expand("query" => "Cafe\u0301")
expect(template.pattern).to eq(
"http://example.com/{resource}/Caf%C3%A9/"
)
end
it "does not normalize unicode when byte semantics requested" do
template = subject.partial_expand({"query" => "Cafe\u0301"}, nil, false)
expect(template.pattern).to eq(
"http://example.com/{resource}/Cafe%CC%81/"
)
end
end
end
describe "Partial expand with strings" do
context "partial_expand with two simple values" do
subject {
Addressable::Template.new("http://example.com/{one}/{two}/")
}
it "builds a new pattern" do
expect(subject.partial_expand("one" => "1").pattern).to eq(
"http://example.com/1/{two}/"
)
end
end
context "partial_expand query with missing param in middle" do
subject {
Addressable::Template.new("http://example.com/{?one,two,three}/")
}
it "builds a new pattern" do
expect(subject.partial_expand("one" => "1", "three" => "3").pattern).to eq(
"http://example.com/?one=1{&two}&three=3/"
)
end
end
context "partial_expand with query string" do
subject {
Addressable::Template.new("http://example.com/{?two,one}/")
}
it "builds a new pattern" do
expect(subject.partial_expand("one" => "1").pattern).to eq(
"http://example.com/?one=1{&two}/"
)
end
end
context "partial_expand with path operator" do
subject {
Addressable::Template.new("http://example.com{/one,two}/")
}
it "builds a new pattern" do
expect(subject.partial_expand("one" => "1").pattern).to eq(
"http://example.com/1{/two}/"
)
end
end
end
describe "Expand" do
context "expand with unicode values" do
subject do
Addressable::Template.new("http://example.com/search/{query}/")
end
it "normalizes unicode by default" do
uri = subject.expand("query" => "Cafe\u0301").to_str
expect(uri).to eq("http://example.com/search/Caf%C3%A9/")
end
it "does not normalize unicode when byte semantics requested" do
uri = subject.expand({ "query" => "Cafe\u0301" }, nil, false).to_str
expect(uri).to eq("http://example.com/search/Cafe%CC%81/")
end
end
context "expand with a processor" do
subject {
Addressable::Template.new("http://example.com/search/{query}/")
}
it "processes spaces" do
expect(subject.expand({"query" => "an example search query"},
ExampleTwoProcessor).to_str).to eq(
"http://example.com/search/an+example+search+query/"
)
end
it "validates" do
expect{
subject.expand({"query" => "Bogus!"},
ExampleTwoProcessor).to_str
}.to raise_error(Addressable::Template::InvalidTemplateValueError)
end
end
context "partial_expand query with missing param in middle" do
subject {
Addressable::Template.new("http://example.com/{?one,two,three}/")
}
it "builds a new pattern" do
expect(subject.partial_expand("one" => "1", "three" => "3").pattern).to eq(
"http://example.com/?one=1{&two}&three=3/"
)
end
end
context "partial_expand with query string" do
subject {
Addressable::Template.new("http://example.com/{?two,one}/")
}
it "builds a new pattern" do
expect(subject.partial_expand("one" => "1").pattern).to eq(
"http://example.com/?one=1{&two}/"
)
end
end
context "partial_expand with path operator" do
subject {
Addressable::Template.new("http://example.com{/one,two}/")
}
it "builds a new pattern" do
expect(subject.partial_expand("one" => "1").pattern).to eq(
"http://example.com/1{/two}/"
)
end
end
end
context "Matching with operators" do
describe "Level 1:" do
subject { Addressable::Template.new("foo{foo}/{bar}baz") }
it "can match" do
data = subject.match("foofoo/bananabaz")
expect(data.mapping["foo"]).to eq("foo")
expect(data.mapping["bar"]).to eq("banana")
end
it "can fail" do
expect(subject.match("bar/foo")).to be_nil
expect(subject.match("foobaz")).to be_nil
end
it "can match empty" do
data = subject.match("foo/baz")
expect(data.mapping["foo"]).to eq(nil)
expect(data.mapping["bar"]).to eq(nil)
end
it "lists vars" do
expect(subject.variables).to eq(["foo", "bar"])
end
end
describe "Level 2:" do
subject { Addressable::Template.new("foo{+foo}{#bar}baz") }
it "can match" do
data = subject.match("foo/test/banana#bazbaz")
expect(data.mapping["foo"]).to eq("/test/banana")
expect(data.mapping["bar"]).to eq("baz")
end
it "can match empty level 2 #" do
data = subject.match("foo/test/bananabaz")
expect(data.mapping["foo"]).to eq("/test/banana")
expect(data.mapping["bar"]).to eq(nil)
data = subject.match("foo/test/banana#baz")
expect(data.mapping["foo"]).to eq("/test/banana")
expect(data.mapping["bar"]).to eq("")
end
it "can match empty level 2 +" do
data = subject.match("foobaz")
expect(data.mapping["foo"]).to eq(nil)
expect(data.mapping["bar"]).to eq(nil)
data = subject.match("foo#barbaz")
expect(data.mapping["foo"]).to eq(nil)
expect(data.mapping["bar"]).to eq("bar")
end
it "lists vars" do
expect(subject.variables).to eq(["foo", "bar"])
end
end
describe "Level 3:" do
context "no operator" do
subject { Addressable::Template.new("foo{foo,bar}baz") }
it "can match" do
data = subject.match("foofoo,barbaz")
expect(data.mapping["foo"]).to eq("foo")
expect(data.mapping["bar"]).to eq("bar")
end
it "lists vars" do
expect(subject.variables).to eq(["foo", "bar"])
end
end
context "+ operator" do
subject { Addressable::Template.new("foo{+foo,bar}baz") }
it "can match" do
data = subject.match("foofoo/bar,barbaz")
expect(data.mapping["bar"]).to eq("foo/bar,bar")
expect(data.mapping["foo"]).to eq("")
end
it "lists vars" do
expect(subject.variables).to eq(["foo", "bar"])
end
end
context ". operator" do
subject { Addressable::Template.new("foo{.foo,bar}baz") }
it "can match" do
data = subject.match("foo.foo.barbaz")
expect(data.mapping["foo"]).to eq("foo")
expect(data.mapping["bar"]).to eq("bar")
end
it "lists vars" do
expect(subject.variables).to eq(["foo", "bar"])
end
end
context "/ operator" do
subject { Addressable::Template.new("foo{/foo,bar}baz") }
it "can match" do
data = subject.match("foo/foo/barbaz")
expect(data.mapping["foo"]).to eq("foo")
expect(data.mapping["bar"]).to eq("bar")
end
it "lists vars" do
expect(subject.variables).to eq(["foo", "bar"])
end
end
context "; operator" do
subject { Addressable::Template.new("foo{;foo,bar,baz}baz") }
it "can match" do
data = subject.match("foo;foo=bar%20baz;bar=foo;bazbaz")
expect(data.mapping["foo"]).to eq("bar baz")
expect(data.mapping["bar"]).to eq("foo")
expect(data.mapping["baz"]).to eq("")
end
it "lists vars" do
expect(subject.variables).to eq(%w(foo bar baz))
end
end
context "? operator" do
context "test" do
subject { Addressable::Template.new("foo{?foo,bar}baz") }
it "can match" do
data = subject.match("foo?foo=bar%20baz&bar=foobaz")
expect(data.mapping["foo"]).to eq("bar baz")
expect(data.mapping["bar"]).to eq("foo")
end
it "lists vars" do
expect(subject.variables).to eq(%w(foo bar))
end
end
context "issue #137" do
subject { Addressable::Template.new('/path{?page,per_page}') }
it "can match empty" do
data = subject.match("/path")
expect(data.mapping["page"]).to eq(nil)
expect(data.mapping["per_page"]).to eq(nil)
expect(data.mapping.keys.sort).to eq(['page', 'per_page'])
end
it "can match first var" do
data = subject.match("/path?page=1")
expect(data.mapping["page"]).to eq("1")
expect(data.mapping["per_page"]).to eq(nil)
expect(data.mapping.keys.sort).to eq(['page', 'per_page'])
end
it "can match second var" do
data = subject.match("/path?per_page=1")
expect(data.mapping["page"]).to eq(nil)
expect(data.mapping["per_page"]).to eq("1")
expect(data.mapping.keys.sort).to eq(['page', 'per_page'])
end
it "can match both vars" do
data = subject.match("/path?page=2&per_page=1")
expect(data.mapping["page"]).to eq("2")
expect(data.mapping["per_page"]).to eq("1")
expect(data.mapping.keys.sort).to eq(['page', 'per_page'])
end
end
context "issue #71" do
subject { Addressable::Template.new("http://cyberscore.dev/api/users{?username}") }
it "can match" do
data = subject.match("http://cyberscore.dev/api/users?username=foobaz")
expect(data.mapping["username"]).to eq("foobaz")
end
it "lists vars" do
expect(subject.variables).to eq(%w(username))
expect(subject.keys).to eq(%w(username))
end
end
end
context "& operator" do
subject { Addressable::Template.new("foo{&foo,bar}baz") }
it "can match" do
data = subject.match("foo&foo=bar%20baz&bar=foobaz")
expect(data.mapping["foo"]).to eq("bar baz")
expect(data.mapping["bar"]).to eq("foo")
end
it "lists vars" do
expect(subject.variables).to eq(%w(foo bar))
end
end
end
end
context "support regexes:" do
context "EXPRESSION" do
subject { Addressable::Template::EXPRESSION }
it "should be able to match an expression" do
expect(subject).to match("{foo}")
expect(subject).to match("{foo,9}")
expect(subject).to match("{foo.bar,baz}")
expect(subject).to match("{+foo.bar,baz}")
expect(subject).to match("{foo,foo%20bar}")
expect(subject).to match("{#foo:20,baz*}")
expect(subject).to match("stuff{#foo:20,baz*}things")
end
it "should fail on non vars" do
expect(subject).not_to match("!{foo")
expect(subject).not_to match("{foo.bar.}")
expect(subject).not_to match("!{}")
end
end
context "VARNAME" do
subject { Addressable::Template::VARNAME }
it "should be able to match a variable" do
expect(subject).to match("foo")
expect(subject).to match("9")
expect(subject).to match("foo.bar")
expect(subject).to match("foo_bar")
expect(subject).to match("foo_bar.baz")
expect(subject).to match("foo%20bar")
expect(subject).to match("foo%20bar.baz")
end
it "should fail on non vars" do
expect(subject).not_to match("!foo")
expect(subject).not_to match("foo.bar.")
expect(subject).not_to match("foo%2%00bar")
expect(subject).not_to match("foo_ba%r")
expect(subject).not_to match("foo_bar*")
expect(subject).not_to match("foo_bar:20")
end
end
context "VARIABLE_LIST" do
subject { Addressable::Template::VARIABLE_LIST }
it "should be able to match a variable list" do
expect(subject).to match("foo,bar")
expect(subject).to match("foo")
expect(subject).to match("foo,bar*,baz")
expect(subject).to match("foo.bar,bar_baz*,baz:12")
end
it "should fail on non vars" do
expect(subject).not_to match(",foo,bar*,baz")
expect(subject).not_to match("foo,*bar,baz")
expect(subject).not_to match("foo,,bar*,baz")
end
end
context "VARSPEC" do
subject { Addressable::Template::VARSPEC }
it "should be able to match a variable with modifier" do
expect(subject).to match("9:8")
expect(subject).to match("foo.bar*")
expect(subject).to match("foo_bar:12")
expect(subject).to match("foo_bar.baz*")
expect(subject).to match("foo%20bar:12")
expect(subject).to match("foo%20bar.baz*")
end
it "should fail on non vars" do
expect(subject).not_to match("!foo")
expect(subject).not_to match("*foo")
expect(subject).not_to match("fo*o")
expect(subject).not_to match("fo:o")
expect(subject).not_to match("foo:")
end
end
end
end
describe Addressable::Template::MatchData do
let(:template) { Addressable::Template.new('{foo}/{bar}') }
subject(:its) { template.match('ab/cd') }
its(:uri) { should == Addressable::URI.parse('ab/cd') }
its(:template) { should == template }
its(:mapping) { should == { 'foo' => 'ab', 'bar' => 'cd' } }
its(:variables) { should == ['foo', 'bar'] }
its(:keys) { should == ['foo', 'bar'] }
its(:names) { should == ['foo', 'bar'] }
its(:values) { should == ['ab', 'cd'] }
its(:captures) { should == ['ab', 'cd'] }
its(:to_a) { should == ['ab/cd', 'ab', 'cd'] }
its(:to_s) { should == 'ab/cd' }
its(:string) { should == its.to_s }
its(:pre_match) { should == "" }
its(:post_match) { should == "" }
describe 'values_at' do
it 'returns an array with the values' do
expect(its.values_at(0, 2)).to eq(['ab/cd', 'cd'])
end
it 'allows mixing integer an string keys' do
expect(its.values_at('foo', 1)).to eq(['ab', 'ab'])
end
it 'accepts unknown keys' do
expect(its.values_at('baz', 'foo')).to eq([nil, 'ab'])
end
end
describe '[]' do
context 'string key' do
it 'returns the corresponding capture' do
expect(its['foo']).to eq('ab')
expect(its['bar']).to eq('cd')
end
it 'returns nil for unknown keys' do
expect(its['baz']).to be_nil
end
end
context 'symbol key' do
it 'returns the corresponding capture' do
expect(its[:foo]).to eq('ab')
expect(its[:bar]).to eq('cd')
end
it 'returns nil for unknown keys' do
expect(its[:baz]).to be_nil
end
end
context 'integer key' do
it 'returns the full URI for index 0' do
expect(its[0]).to eq('ab/cd')
end
it 'returns the corresponding capture' do
expect(its[1]).to eq('ab')
expect(its[2]).to eq('cd')
end
it 'returns nil for unknown keys' do
expect(its[3]).to be_nil
end
end
context 'other key' do
it 'raises an exception' do
expect { its[Object.new] }.to raise_error(TypeError)
end
end
context 'with length' do
it 'returns an array starting at index with given length' do
expect(its[0, 2]).to eq(['ab/cd', 'ab'])
expect(its[2, 1]).to eq(['cd'])
end
end
end
end
addressable-2.7.0/spec/addressable/rack_mount_compat_spec.rb 0000644 0000041 0000041 00000006423 13534474053 024305 0 ustar www-data www-data # frozen_string_literal: true
# coding: utf-8
# Copyright (C) Bob Aman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require "spec_helper"
require "addressable/uri"
require "addressable/template"
require "rack/mount"
describe Rack::Mount do
let(:app_one) do
proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 1'] }
end
let(:app_two) do
proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 2'] }
end
let(:app_three) do
proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 3'] }
end
let(:routes) do
s = Rack::Mount::RouteSet.new do |set|
set.add_route(app_one, {
:request_method => 'GET',
:path_info => Addressable::Template.new('/one/{id}/')
}, {:id => 'unidentified'}, :one)
set.add_route(app_two, {
:request_method => 'GET',
:path_info => Addressable::Template.new('/two/')
}, {:id => 'unidentified'}, :two)
set.add_route(app_three, {
:request_method => 'GET',
:path_info => Addressable::Template.new('/three/{id}/').to_regexp
}, {:id => 'unidentified'}, :three)
end
s.rehash
s
end
it "should generate from routes with Addressable::Template" do
path, _ = routes.generate(:path_info, :one, {:id => '123'})
expect(path).to eq '/one/123/'
end
it "should generate from routes with Addressable::Template using defaults" do
path, _ = routes.generate(:path_info, :one, {})
expect(path).to eq '/one/unidentified/'
end
it "should recognize routes with Addressable::Template" do
request = Rack::Request.new(
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/one/123/'
)
route, _, params = routes.recognize(request)
expect(route).not_to be_nil
expect(route.app).to eq app_one
expect(params).to eq({id: '123'})
end
it "should generate from routes with Addressable::Template" do
path, _ = routes.generate(:path_info, :two, {:id => '654'})
expect(path).to eq '/two/'
end
it "should generate from routes with Addressable::Template using defaults" do
path, _ = routes.generate(:path_info, :two, {})
expect(path).to eq '/two/'
end
it "should recognize routes with Addressable::Template" do
request = Rack::Request.new(
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/two/'
)
route, _, params = routes.recognize(request)
expect(route).not_to be_nil
expect(route.app).to eq app_two
expect(params).to eq({id: 'unidentified'})
end
it "should recognize routes with derived Regexp" do
request = Rack::Request.new(
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/three/789/'
)
route, _, params = routes.recognize(request)
expect(route).not_to be_nil
expect(route.app).to eq app_three
expect(params).to eq({id: '789'})
end
end
addressable-2.7.0/spec/addressable/security_spec.rb 0000644 0000041 0000041 00000004262 13534474053 022446 0 ustar www-data www-data # frozen_string_literal: true
# coding: utf-8
# Copyright (C) Bob Aman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require "spec_helper"
require "addressable/uri"
describe Addressable::URI, "when created with a URI known to cause crashes " +
"in certain browsers" do
it "should parse correctly" do
uri = Addressable::URI.parse('%%30%30')
expect(uri.path).to eq('%%30%30')
expect(uri.normalize.path).to eq('%2500')
end
it "should parse correctly as a full URI" do
uri = Addressable::URI.parse('http://www.example.com/%%30%30')
expect(uri.path).to eq('/%%30%30')
expect(uri.normalize.path).to eq('/%2500')
end
end
describe Addressable::URI, "when created with a URI known to cause crashes " +
"in certain browsers" do
it "should parse correctly" do
uri = Addressable::URI.parse('لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
expect(uri.path).to eq('لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
expect(uri.normalize.path).to eq(
'%D9%84%D9%8F%D8%B5%D9%91%D8%A8%D9%8F%D9%84%D9%8F%D9%84%D8%B5%D9%91' +
'%D8%A8%D9%8F%D8%B1%D8%B1%D9%8B%20%E0%A5%A3%20%E0%A5%A3h%20%E0%A5' +
'%A3%20%E0%A5%A3%20%E5%86%97'
)
end
it "should parse correctly as a full URI" do
uri = Addressable::URI.parse('http://www.example.com/لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
expect(uri.path).to eq('/لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
expect(uri.normalize.path).to eq(
'/%D9%84%D9%8F%D8%B5%D9%91%D8%A8%D9%8F%D9%84%D9%8F%D9%84%D8%B5%D9%91' +
'%D8%A8%D9%8F%D8%B1%D8%B1%D9%8B%20%E0%A5%A3%20%E0%A5%A3h%20%E0%A5' +
'%A3%20%E0%A5%A3%20%E5%86%97'
)
end
end
addressable-2.7.0/spec/addressable/idna_spec.rb 0000644 0000041 0000041 00000024277 13534474053 021522 0 ustar www-data www-data # frozen_string_literal: true
# coding: utf-8
# Copyright (C) Bob Aman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require "spec_helper"
# Have to use RubyGems to load the idn gem.
require "rubygems"
require "addressable/idna"
shared_examples_for "converting from unicode to ASCII" do
it "should convert 'www.google.com' correctly" do
expect(Addressable::IDNA.to_ascii("www.google.com")).to eq("www.google.com")
end
long = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
it "should convert '#{long}' correctly" do
expect(Addressable::IDNA.to_ascii(long)).to eq(long)
end
it "should convert 'www.詹姆斯.com' correctly" do
expect(Addressable::IDNA.to_ascii(
"www.詹姆斯.com"
)).to eq("www.xn--8ws00zhy3a.com")
end
it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
"www.Iñtërnâtiônàlizætiøn.com"
expect(Addressable::IDNA.to_ascii(
"www.I\xC3\xB1t\xC3\xABrn\xC3\xA2ti\xC3\xB4" +
"n\xC3\xA0liz\xC3\xA6ti\xC3\xB8n.com"
)).to eq("www.xn--itrntinliztin-vdb0a5exd8ewcye.com")
end
it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
expect(Addressable::IDNA.to_ascii(
"www.In\xCC\x83te\xCC\x88rna\xCC\x82tio\xCC\x82n" +
"a\xCC\x80liz\xC3\xA6ti\xC3\xB8n.com"
)).to eq("www.xn--itrntinliztin-vdb0a5exd8ewcye.com")
end
it "should convert " +
"'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
"correctly" do
expect(Addressable::IDNA.to_ascii(
"www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
"\201\252\343\201\214\343\201\204\343\202\217\343\201\221\343\201\256" +
"\343\202\217\343\201\213\343\202\211\343\201\252\343\201\204\343\201" +
"\251\343\202\201\343\201\204\343\202\223\343\202\201\343\201\204\343" +
"\201\256\343\202\211\343\201\271\343\202\213\343\201\276\343\201\240" +
"\343\201\252\343\201\214\343\201\217\343\201\227\343\201\252\343\201" +
"\204\343\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
"w3.mag.keio.ac.jp"
)).to eq(
"www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
"fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
)
end
it "should convert " +
"'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
"correctly" do
expect(Addressable::IDNA.to_ascii(
"www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
"\201\252\343\201\213\343\202\231\343\201\204\343\202\217\343\201\221" +
"\343\201\256\343\202\217\343\201\213\343\202\211\343\201\252\343\201" +
"\204\343\201\250\343\202\231\343\202\201\343\201\204\343\202\223\343" +
"\202\201\343\201\204\343\201\256\343\202\211\343\201\270\343\202\231" +
"\343\202\213\343\201\276\343\201\237\343\202\231\343\201\252\343\201" +
"\213\343\202\231\343\201\217\343\201\227\343\201\252\343\201\204\343" +
"\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
"w3.mag.keio.ac.jp"
)).to eq(
"www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
"fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
)
end
it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
expect(Addressable::IDNA.to_ascii(
"点心和烤鸭.w3.mag.keio.ac.jp"
)).to eq("xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp")
end
it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
expect(Addressable::IDNA.to_ascii(
"가각갂갃간갅갆갇갈갉힢힣.com"
)).to eq("xn--o39acdefghijk5883jma.com")
end
it "should convert " +
"'\347\242\274\346\250\231\346\272\226\350" +
"\220\254\345\234\213\347\242\274.com' correctly" do
expect(Addressable::IDNA.to_ascii(
"\347\242\274\346\250\231\346\272\226\350" +
"\220\254\345\234\213\347\242\274.com"
)).to eq("xn--9cs565brid46mda086o.com")
end
it "should convert 'リ宠퐱〹.com' correctly" do
expect(Addressable::IDNA.to_ascii(
"\357\276\230\345\256\240\355\220\261\343\200\271.com"
)).to eq("xn--eek174hoxfpr4k.com")
end
it "should convert 'リ宠퐱卄.com' correctly" do
expect(Addressable::IDNA.to_ascii(
"\343\203\252\345\256\240\355\220\261\345\215\204.com"
)).to eq("xn--eek174hoxfpr4k.com")
end
it "should convert 'ᆵ' correctly" do
expect(Addressable::IDNA.to_ascii(
"\341\206\265"
)).to eq("xn--4ud")
end
it "should convert 'ᆵ' correctly" do
expect(Addressable::IDNA.to_ascii(
"\357\276\257"
)).to eq("xn--4ud")
end
it "should convert '🌹🌹🌹.ws' correctly" do
expect(Addressable::IDNA.to_ascii(
"\360\237\214\271\360\237\214\271\360\237\214\271.ws"
)).to eq("xn--2h8haa.ws")
end
it "should handle two adjacent '.'s correctly" do
expect(Addressable::IDNA.to_ascii(
"example..host"
)).to eq("example..host")
end
end
shared_examples_for "converting from ASCII to unicode" do
long = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
it "should convert '#{long}' correctly" do
expect(Addressable::IDNA.to_unicode(long)).to eq(long)
end
it "should return the identity conversion when punycode decode fails" do
expect(Addressable::IDNA.to_unicode("xn--zckp1cyg1.sblo.jp")).to eq(
"xn--zckp1cyg1.sblo.jp")
end
it "should return the identity conversion when the ACE prefix has no suffix" do
expect(Addressable::IDNA.to_unicode("xn--...-")).to eq("xn--...-")
end
it "should convert 'www.google.com' correctly" do
expect(Addressable::IDNA.to_unicode("www.google.com")).to eq(
"www.google.com")
end
it "should convert 'www.詹姆斯.com' correctly" do
expect(Addressable::IDNA.to_unicode(
"www.xn--8ws00zhy3a.com"
)).to eq("www.詹姆斯.com")
end
it "should convert '詹姆斯.com' correctly" do
expect(Addressable::IDNA.to_unicode(
"xn--8ws00zhy3a.com"
)).to eq("詹姆斯.com")
end
it "should convert 'www.iñtërnâtiônàlizætiøn.com' correctly" do
expect(Addressable::IDNA.to_unicode(
"www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
)).to eq("www.iñtërnâtiônàlizætiøn.com")
end
it "should convert 'iñtërnâtiônàlizætiøn.com' correctly" do
expect(Addressable::IDNA.to_unicode(
"xn--itrntinliztin-vdb0a5exd8ewcye.com"
)).to eq("iñtërnâtiônàlizætiøn.com")
end
it "should convert " +
"'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
"correctly" do
expect(Addressable::IDNA.to_unicode(
"www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
"fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
)).to eq(
"www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp"
)
end
it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
expect(Addressable::IDNA.to_unicode(
"xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp"
)).to eq("点心和烤鸭.w3.mag.keio.ac.jp")
end
it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
expect(Addressable::IDNA.to_unicode(
"xn--o39acdefghijk5883jma.com"
)).to eq("가각갂갃간갅갆갇갈갉힢힣.com")
end
it "should convert " +
"'\347\242\274\346\250\231\346\272\226\350" +
"\220\254\345\234\213\347\242\274.com' correctly" do
expect(Addressable::IDNA.to_unicode(
"xn--9cs565brid46mda086o.com"
)).to eq(
"\347\242\274\346\250\231\346\272\226\350" +
"\220\254\345\234\213\347\242\274.com"
)
end
it "should convert 'リ宠퐱卄.com' correctly" do
expect(Addressable::IDNA.to_unicode(
"xn--eek174hoxfpr4k.com"
)).to eq("\343\203\252\345\256\240\355\220\261\345\215\204.com")
end
it "should convert 'ᆵ' correctly" do
expect(Addressable::IDNA.to_unicode(
"xn--4ud"
)).to eq("\341\206\265")
end
it "should convert '🌹🌹🌹.ws' correctly" do
expect(Addressable::IDNA.to_unicode(
"xn--2h8haa.ws"
)).to eq("\360\237\214\271\360\237\214\271\360\237\214\271.ws")
end
it "should handle two adjacent '.'s correctly" do
expect(Addressable::IDNA.to_unicode(
"example..host"
)).to eq("example..host")
end
it "should normalize 'string' correctly" do
expect(Addressable::IDNA.unicode_normalize_kc(:'string')).to eq("string")
expect(Addressable::IDNA.unicode_normalize_kc("string")).to eq("string")
end
end
describe Addressable::IDNA, "when using the pure-Ruby implementation" do
before do
Addressable.send(:remove_const, :IDNA)
load "addressable/idna/pure.rb"
end
it_should_behave_like "converting from unicode to ASCII"
it_should_behave_like "converting from ASCII to unicode"
begin
require "fiber"
it "should not blow up inside fibers" do
f = Fiber.new do
Addressable.send(:remove_const, :IDNA)
load "addressable/idna/pure.rb"
end
f.resume
end
rescue LoadError
# Fibers aren't supported in this version of Ruby, skip this test.
warn('Fibers unsupported.')
end
end
begin
require "idn"
describe Addressable::IDNA, "when using the native-code implementation" do
before do
Addressable.send(:remove_const, :IDNA)
load "addressable/idna/native.rb"
end
it_should_behave_like "converting from unicode to ASCII"
it_should_behave_like "converting from ASCII to unicode"
end
rescue LoadError
# Cannot test the native implementation without libidn support.
warn('Could not load native IDN implementation.')
end
addressable-2.7.0/spec/addressable/net_http_compat_spec.rb 0000644 0000041 0000041 00000001636 13534474053 023771 0 ustar www-data www-data # frozen_string_literal: true
# coding: utf-8
# Copyright (C) Bob Aman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require "spec_helper"
require "addressable/uri"
require "net/http"
describe Net::HTTP do
it "should be compatible with Addressable" do
response_body =
Net::HTTP.get(Addressable::URI.parse('http://www.google.com/'))
expect(response_body).not_to be_nil
end
end
addressable-2.7.0/spec/spec_helper.rb 0000644 0000041 0000041 00000000712 13534474053 017601 0 ustar www-data www-data # frozen_string_literal: true
require 'bundler/setup'
require 'rspec/its'
begin
require 'coveralls'
Coveralls.wear! do
add_filter "spec/"
add_filter "vendor/"
end
rescue LoadError
warn "warning: coveralls gem not found; skipping Coveralls"
require 'simplecov'
SimpleCov.start do
add_filter "spec/"
add_filter "vendor/"
end
end
RSpec.configure do |config|
config.warnings = true
config.filter_run_when_matching :focus
end
addressable-2.7.0/CHANGELOG.md 0000644 0000041 0000041 00000020717 13534474053 015651 0 ustar www-data www-data # Addressable 2.7.0
- added `:compacted` flag to `normalized_query`
- `heuristic_parse` handles `mailto:` more intuitively
- refactored validation to use a prepended module
- dropped explicit support for JRuby 9.0.5.0
- compatibility w/ public_suffix 4.x
- performance improvements
# Addressable 2.6.0
- added `tld=` method to allow assignment to the public suffix
- most `heuristic_parse` patterns are now case-insensitive
- `heuristic_parse` handles more `file://` URI variations
- fixes bug in `heuristic_parse` when uri starts with digit
- fixes bug in `request_uri=` with query strings
- fixes template issues with `nil` and `?` operator
- `frozen_string_literal` pragmas added
- minor performance improvements in regexps
- fixes to eliminate warnings
# Addressable 2.5.2
- better support for frozen string literals
- fixed bug w/ uppercase characters in scheme
- IDNA errors w/ emoji URLs
- compatibility w/ public_suffix 3.x
# Addressable 2.5.1
- allow unicode normalization to be disabled for URI Template expansion
- removed duplicate test
# Addressable 2.5.0
- dropping support for Ruby 1.9
- adding support for Ruby 2.4 preview
- add support for public suffixes and tld; first runtime dependency
- hostname escaping should match RFC; underscores in hostnames no longer escaped
- paths beginning with // and missing an authority are now considered invalid
- validation now also takes place after setting a path
- handle backslashes in authority more like a browser for `heuristic_parse`
- unescaped backslashes in host now raise an `InvalidURIError`
- `merge!`, `join!`, `omit!` and `normalize!` don't disable deferred validation
- `heuristic_parse` now trims whitespace before parsing
- host parts longer than 63 bytes will be ignored and not passed to libidn
- normalized values always encoded as UTF-8
# Addressable 2.4.0
- support for 1.8.x dropped
- double quotes in a host now raises an error
- newlines in host will no longer get unescaped during normalization
- stricter handling of bogus scheme values
- stricter handling of encoded port values
- calling `require 'addressable'` will now load both the URI and Template files
- assigning to the `hostname` component with an `IPAddr` object is now supported
- assigning to the `origin` component is now supported
- fixed minor bug where an exception would be thrown for a missing ACE suffix
- better partial expansion of URI templates
# Addressable 2.3.8
- fix warnings
- update dependency gems
- support for 1.8.x officially deprecated
# Addressable 2.3.7
- fix scenario in which invalid URIs don't get an exception until inspected
- handle hostnames with two adjacent periods correctly
- upgrade of RSpec
# Addressable 2.3.6
- normalization drops empty query string
- better handling in template extract for missing values
- template modifier for `'?'` now treated as optional
- fixed issue where character class parameters were modified
- templates can now be tested for equality
- added `:sorted` option to normalization of query strings
- fixed issue with normalization of hosts given in `'example.com.'` form
# Addressable 2.3.5
- added Addressable::URI#empty? method
- Addressable::URI#hostname methods now strip square brackets from IPv6 hosts
- compatibility with Net::HTTP in Ruby 2.0.0
- Addressable::URI#route_from should always give relative URIs
# Addressable 2.3.4
- fixed issue with encoding altering its inputs
- query string normalization now leaves ';' characters alone
- FakeFS is detected before attempting to load unicode tables
- additional testing to ensure frozen objects don't cause problems
# Addressable 2.3.3
- fixed issue with converting common primitives during template expansion
- fixed port encoding issue
- removed a few warnings
- normalize should now ignore %2B in query strings
- the IDNA logic should now be handled by libidn in Ruby 1.9
- no template match should now result in nil instead of an empty MatchData
- added license information to gemspec
# Addressable 2.3.2
- added Addressable::URI#default_port method
- fixed issue with Marshalling Unicode data on Windows
- improved heuristic parsing to better handle IPv4 addresses
# Addressable 2.3.1
- fixed missing unicode data file
# Addressable 2.3.0
- updated Addressable::Template to use RFC 6570, level 4
- fixed compatibility problems with some versions of Ruby
- moved unicode tables into a data file for performance reasons
- removing support for multiple query value notations
# Addressable 2.2.8
- fixed issues with dot segment removal code
- form encoding can now handle multiple values per key
- updated development environment
# Addressable 2.2.7
- fixed issues related to Addressable::URI#query_values=
- the Addressable::URI.parse method is now polymorphic
# Addressable 2.2.6
- changed the way ambiguous paths are handled
- fixed bug with frozen URIs
- https supported in heuristic parsing
# Addressable 2.2.5
- 'parsing' a pre-parsed URI object is now a dup operation
- introduced conditional support for libidn
- fixed normalization issue on ampersands in query strings
- added additional tests around handling of query strings
# Addressable 2.2.4
- added origin support from draft-ietf-websec-origin-00
- resolved issue with attempting to navigate below root
- fixed bug with string splitting in query strings
# Addressable 2.2.3
- added :flat_array notation for query strings
# Addressable 2.2.2
- fixed issue with percent escaping of '+' character in query strings
# Addressable 2.2.1
- added support for application/x-www-form-urlencoded.
# Addressable 2.2.0
- added site methods
- improved documentation
# Addressable 2.1.2
- added HTTP request URI methods
- better handling of Windows file paths
- validation_deferred boolean replaced with defer_validation block
- normalization of percent-encoded paths should now be correct
- fixed issue with constructing URIs with relative paths
- fixed warnings
# Addressable 2.1.1
- more type checking changes
- fixed issue with unicode normalization
- added method to find template defaults
- symbolic keys are now allowed in template mappings
- numeric values and symbolic values are now allowed in template mappings
# Addressable 2.1.0
- refactored URI template support out into its own class
- removed extract method due to being useless and unreliable
- removed Addressable::URI.expand_template
- removed Addressable::URI#extract_mapping
- added partial template expansion
- fixed minor bugs in the parse and heuristic_parse methods
- fixed incompatibility with Ruby 1.9.1
- fixed bottleneck in Addressable::URI#hash and Addressable::URI#to_s
- fixed unicode normalization exception
- updated query_values methods to better handle subscript notation
- worked around issue with freezing URIs
- improved specs
# Addressable 2.0.2
- fixed issue with URI template expansion
- fixed issue with percent escaping characters 0-15
# Addressable 2.0.1
- fixed issue with query string assignment
- fixed issue with improperly encoded components
# Addressable 2.0.0
- the initialize method now takes an options hash as its only parameter
- added query_values method to URI class
- completely replaced IDNA implementation with pure Ruby
- renamed Addressable::ADDRESSABLE_VERSION to Addressable::VERSION
- completely reworked the Rakefile
- changed the behavior of the port method significantly
- Addressable::URI.encode_segment, Addressable::URI.unencode_segment renamed
- documentation is now in YARD format
- more rigorous type checking
- to_str method implemented, implicit conversion to Strings now allowed
- Addressable::URI#omit method added, Addressable::URI#merge method replaced
- updated URI Template code to match v 03 of the draft spec
- added a bunch of new specifications
# Addressable 1.0.4
- switched to using RSpec's pending system for specs that rely on IDN
- fixed issue with creating URIs with paths that are not prefixed with '/'
# Addressable 1.0.3
- implemented a hash method
# Addressable 1.0.2
- fixed minor bug with the extract_mapping method
# Addressable 1.0.1
- fixed minor bug with the extract_mapping method
# Addressable 1.0.0
- heuristic parse method added
- parsing is slightly more strict
- replaced to_h with to_hash
- fixed routing methods
- improved specifications
- improved heckle rake task
- no surviving heckle mutations
# Addressable 0.1.2
- improved normalization
- fixed bug in joining algorithm
- updated specifications
# Addressable 0.1.1
- updated documentation
- added URI Template variable extraction
# Addressable 0.1.0
- initial release
- implementation based on RFC 3986, 3987
- support for IRIs via libidn
- support for the URI Template draft spec
addressable-2.7.0/addressable.gemspec 0000644 0000041 0000041 00000005125 13534474053 017652 0 ustar www-data www-data #########################################################
# This file has been automatically generated by gem2tgz #
#########################################################
# -*- encoding: utf-8 -*-
# stub: addressable 2.7.0 ruby lib
Gem::Specification.new do |s|
s.name = "addressable".freeze
s.version = "2.7.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["Bob Aman".freeze]
s.date = "2019-08-31"
s.description = "Addressable is an alternative implementation to the URI implementation that is\npart of Ruby's standard library. It is flexible, offers heuristic parsing, and\nadditionally provides extensive support for IRIs and URI templates.\n".freeze
s.email = "bob@sporkmonger.com".freeze
s.extra_rdoc_files = ["README.md".freeze]
s.files = ["CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE.txt".freeze, "README.md".freeze, "Rakefile".freeze, "data/unicode.data".freeze, "lib/addressable.rb".freeze, "lib/addressable/idna.rb".freeze, "lib/addressable/idna/native.rb".freeze, "lib/addressable/idna/pure.rb".freeze, "lib/addressable/template.rb".freeze, "lib/addressable/uri.rb".freeze, "lib/addressable/version.rb".freeze, "spec/addressable/idna_spec.rb".freeze, "spec/addressable/net_http_compat_spec.rb".freeze, "spec/addressable/rack_mount_compat_spec.rb".freeze, "spec/addressable/security_spec.rb".freeze, "spec/addressable/template_spec.rb".freeze, "spec/addressable/uri_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tasks/clobber.rake".freeze, "tasks/gem.rake".freeze, "tasks/git.rake".freeze, "tasks/metrics.rake".freeze, "tasks/rspec.rake".freeze, "tasks/yard.rake".freeze]
s.homepage = "https://github.com/sporkmonger/addressable".freeze
s.licenses = ["Apache-2.0".freeze]
s.rdoc_options = ["--main".freeze, "README.md".freeze]
s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
s.rubygems_version = "2.5.2.1".freeze
s.summary = "URI Implementation".freeze
if s.respond_to? :specification_version then
s.specification_version = 4
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q.freeze, ["< 3.0", ">= 1.0"])
s.add_runtime_dependency(%q.freeze, ["< 5.0", ">= 2.0.2"])
else
s.add_dependency(%q.freeze, ["< 3.0", ">= 1.0"])
s.add_dependency(%q.freeze, ["< 5.0", ">= 2.0.2"])
end
else
s.add_dependency(%q.freeze, ["< 3.0", ">= 1.0"])
s.add_dependency(%q.freeze, ["< 5.0", ">= 2.0.2"])
end
end
addressable-2.7.0/data/ 0000755 0000041 0000041 00000000000 13534474053 014742 5 ustar www-data www-data addressable-2.7.0/data/unicode.data 0000644 0000041 0000041 00000342034 13534474053 017231 0 ustar www-data www-data {iF[i i 000if0iG[i i 000ig0iH[i i 000ih0iI[i i 000ii0iJ[i i 000ij0iK[i i 000ik0iL[i i 000il0iM[i i 000im0iN[i i 000in0iO[i i 000io0iP[i i 000ip0iQ[i i 000iq0iR[i i 000ir0iS[i i 000is0iT[i i 000it0iU[i i 000iu0iV[i i 000iv0iW[i i 000iw0iX[i i 000ix0iY[i i 000iy0iZ[i i 000iz0i[[i i 000i{0i\[i i 000i|0i][i i 000i}0i^[i i 000i~0i_[i i 000i0if[i i 00iF0iFig[i i 00iG0iGih[i i 00iH0iHii[i i 00iI0iIij[i i 00iJ0iJik[i i 00iK0iKil[i i 00iL0iLim[i i 00iM0iMin[i i 00iN0iNio[i i 00iO0iOip[i i 00iP0iPiq[i i 00iQ0iQir[i i 00iR0iRis[i i 00iS0iSit[i i 00iT0iTiu[i i 00iU0iUiv[i i 00iV0iViw[i i 00iW0iWix[i i 00iX0iXiy[i i 00iY0iYiz[i i 00iZ0iZi{[i i 00i[0i[i|[i i 00i\0i\i}[i i 00i]0i]i~[i i 00i^0i^i[i i 00i_0i_i[i i 0I" :ET000i[i i 0I" ̈; T000i[i i 0I"a; T000i[i i 0I" ̄; T000i[i i 0I"2; T000i[i i 0I"3; T000i[i i 0I" ́; T000i[i i 0I"μ; Ti0ii[i i 0I" ̧; T000i[i i 0I"1; T000i[i i 0I"o; T000i[i i 0I"
1⁄4; T000i[i i 0I"
1⁄2; T000i[i i 0I"
3⁄4; T000i[i i I"À; TI"À; T0i0i[i i I"Á; TI"Á; T0i0i[i i I"Â; TI"Â; T0i0i[i i I"Ã; TI"Ã; T0i0i[i i I"Ä; TI"Ä; T0i0i[i i I"Å; TI"Å; T0i0i[i i 000i0i[i i I"Ç; TI"Ç; T0i0i[i i I"È; TI"È; T0i0i[i i I"É; TI"É; T0i0i[i i I"Ê; TI"Ê; T0i0i[i i I"Ë; TI"Ë; T0i0i[i i I"Ì; TI"Ì; T0i0i[i i I"Í; TI"Í; T0i0i[i i I"Î; TI"Î; T0i0i[i i I"Ï; TI"Ï; T0i0i[i i 000i0i[i i I"Ñ; TI"Ñ; T0i0i[i i I"Ò; TI"Ò; T0i0i[i i I"Ó; TI"Ó; T0i0i[i i I"Ô; TI"Ô; T0i0i[i i I"Õ; TI"Õ; T0i0i[i i I"Ö; TI"Ö; T0i0i[i i 000i0i[i i I"Ù; TI"Ù; T0i0i[i i I"Ú; TI"Ú; T0i0i[i i I"Û; TI"Û; T0i0i[i i I"Ü; TI"Ü; T0i0i[i i I"Ý; TI"Ý; T0i0i[i i 000i0i[i i I"à; TI"à; Ti0ii[i i I"á; TI"á; Ti0ii[i i I"â; TI"â; Ti0ii[i i I"ã; TI"ã; Ti0ii[i i I"ä; TI"ä; Ti0ii[i i I"å; TI"å; Ti0ii[i i 00i0ii[i i I"ç; TI"ç; Ti0ii[i i I"è; TI"è; Ti0ii[i i I"é; TI"é; Ti0ii[i i I"ê; TI"ê; Ti0ii[i i I"ë; TI"ë; Ti0ii[i i I"ì; TI"ì; Ti0ii[i i I"í; TI"í; Ti0ii[i i I"î; TI"î; Ti0ii[i i I"ï; TI"ï; Ti0ii[i i 00i0ii[i i I"ñ; TI"ñ; Ti0ii[i i I"ò; TI"ò; Ti0ii[i i I"ó; TI"ó; Ti0ii[i i I"ô; TI"ô; Ti0ii[i i I"õ; TI"õ; Ti0ii[i i I"ö; TI"ö; Ti0ii[i i 00i0ii[i i I"ù; TI"ù; Ti0ii[i i I"ú; TI"ú; Ti0ii[i i I"û; TI"û; Ti0ii[i i I"ü; TI"ü; Ti0ii[i i I"ý; TI"ý; Ti0ii[i i 00i0ii[i i I"ÿ; TI"ÿ; Tix0ixi [i i I"Ā; TI"Ā; T0i0i[i i I"ā; TI"ā; Ti 0i i[i i I"Ă; TI"Ă; T0i0i[i i I"ă; TI"ă; Ti0ii[i i I"Ą; TI"Ą; T0i0i[i i I"ą; TI"ą; Ti0ii[i i I"Ć; TI"Ć; T0i0i[i i I"ć; TI"ć; Ti0ii[i i I"Ĉ; TI"Ĉ; T0i 0i [i i I"ĉ; TI"ĉ; Ti0ii
[i i I"Ċ; TI"Ċ; T0i0i[i i I"ċ; TI"ċ; Ti
0i
i[i i I"Č; TI"Č; T0i
0i
[i i I"č; TI"č; Ti0ii[i i I"Ď; TI"Ď; T0i0i[i i I"ď; TI"ď; Ti0ii[i i 000i0i[i i 00i0ii[i i I"Ē; TI"Ē; T0i0i[i i I"ē; TI"ē; Ti0ii[i i I"Ĕ; TI"Ĕ; T0i0i[i i I"ĕ; TI"ĕ; Ti0ii[i i I"Ė; TI"Ė; T0i0i[i i I"ė; TI"ė; Ti0ii[i i I"Ę; TI"Ę; T0i0i[i i I"ę; TI"ę; Ti0ii[i i I"Ě; TI"Ě; T0i0i[i i I"ě; TI"ě; Ti0ii[i i I"Ĝ; TI"Ĝ; T0i0i[i i I"ĝ; TI"ĝ; Ti0ii[i i I"Ğ; TI"Ğ; T0i0i[i i I"ğ; TI"ğ; Ti0ii [i i I"Ġ; TI"Ġ; T0i!0i![i i I"ġ; TI"ġ; Ti 0i i"[i i I"Ģ; TI"Ģ; T0i#0i#[i i I"ģ; TI"ģ; Ti"0i"i$[i i I"Ĥ; TI"Ĥ; T0i%0i%[i i I"ĥ; TI"ĥ; Ti$0i$i&[i i 000i'0i'[i i 00i&0i&i([i i I"Ĩ; TI"Ĩ; T0i)0i)[i i I"ĩ; TI"ĩ; Ti(0i(i*[i i I"Ī; TI"Ī; T0i+0i+[i i I"ī; TI"ī; Ti*0i*i,[i i I"Ĭ; TI"Ĭ; T0i-0i-[i i I"ĭ; TI"ĭ; Ti,0i,i.[i i I"Į; TI"Į; T0i/0i/[i i I"į; TI"į; Ti.0i.i0[i i I"İ; TI"İ; T0in0i1[i i 00iN0iNi2[i i 0I"IJ; T0i30i3[i i 0I"ij; Ti20i2i4[i i I"Ĵ; TI"Ĵ; T0i50i5[i i I"ĵ; TI"ĵ; Ti40i4i6[i i I"Ķ; TI"Ķ; T0i70i7[i i I"ķ; TI"ķ; Ti60i6i9[i i I"Ĺ; TI"Ĺ; T0i:0i:[i i I"ĺ; TI"ĺ; Ti90i9i;[i i I"Ļ; TI"Ļ; T0i<0i<[i i I"ļ; TI"ļ; Ti;0i;i=[i i I"Ľ; TI"Ľ; T0i>0i>[i i I"ľ; TI"ľ; Ti=0i=i?[i i 0I"L·; T0i@0i@[i i 0I"l·; Ti?0i?iA[i i 000iB0iB[i i 00iA0iAiC[i i I"Ń; TI"Ń; T0iD0iD[i i I"ń; TI"ń; TiC0iCiE[i i I"Ņ; TI"Ņ; T0iF0iF[i i I"ņ; TI"ņ; TiE0iEiG[i i I"Ň; TI"Ň; T0iH0iH[i i I"ň; TI"ň; TiG0iGiI[i i 0I"ʼn; T000iJ[i i 000iK0iK[i i 00iJ0iJiL[i i I"Ō; TI"Ō; T0iM0iM[i i I"ō; TI"ō; TiL0iLiN[i i I"Ŏ; TI"Ŏ; T0iO0iO[i i I"ŏ; TI"ŏ; TiN0iNiP[i i I"Ő; TI"Ő; T0iQ0iQ[i i I"ő; TI"ő; TiP0iPiR[i i 000iS0iS[i i 00iR0iRiT[i i I"Ŕ; TI"Ŕ; T0iU0iU[i i I"ŕ; TI"ŕ; TiT0iTiV[i i I"Ŗ; TI"Ŗ; T0iW0iW[i i I"ŗ; TI"ŗ; TiV0iViX[i i I"Ř; TI"Ř; T0iY0iY[i i I"ř; TI"ř; TiX0iXiZ[i i I"Ś; TI"Ś; T0i[0i[[i i I"ś; TI"ś; TiZ0iZi\[i i I"Ŝ; TI"Ŝ; T0i]0i][i i I"ŝ; TI"ŝ; Ti\0i\i^[i i I"Ş; TI"Ş; T0i_0i_[i i I"ş; TI"ş; Ti^0i^i`[i i I"Š; TI"Š; T0ia0ia[i i I"š; TI"š; Ti`0i`ib[i i I"Ţ; TI"Ţ; T0ic0ic[i i I"ţ; TI"ţ; Tib0ibid[i i I"Ť; TI"Ť; T0ie0ie[i i I"ť; TI"ť; Tid0idif[i i 000ig0ig[i i 00if0ifih[i i I"Ũ; TI"Ũ; T0ii0ii[i i I"ũ; TI"ũ; Tih0ihij[i i I"Ū; TI"Ū; T0ik0ik[i i I"ū; TI"ū; Tij0ijil[i i I"Ŭ; TI"Ŭ; T0im0im[i i I"ŭ; TI"ŭ; Til0ilin[i i I"Ů; TI"Ů; T0io0io[i i I"ů; TI"ů; Tin0inip[i i I"Ű; TI"Ű; T0iq0iq[i i I"ű; TI"ű; Tip0ipir[i i I"Ų; TI"Ų; T0is0is[i i I"ų; TI"ų; Tir0irit[i i I"Ŵ; TI"Ŵ; T0iu0iu[i i I"ŵ; TI"ŵ; Tit0itiv[i i I"Ŷ; TI"Ŷ; T0iw0iw[i i I"ŷ; TI"ŷ; Tiv0ivix[i i I"Ÿ; TI"Ÿ; T0i0iy[i i I"Ź; TI"Ź; T0iz0iz[i i I"ź; TI"ź; Tiy0iyi{[i i I"Ż; TI"Ż; T0i|0i|[i i I"ż; TI"ż; Ti{0i{i}[i i I"Ž; TI"Ž; T0i~0i~[i i I"ž; TI"ž; Ti}0i}i[i i 0I"s; TiX0iXi[i i 000iS0i[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000iT0i[i i 000i0i[i i 00i0ii[i i 000iV0i[i i 000iW0i[i i 000i0i[i i 00i0ii[i i 000i0i[i i 000iY0i[i i 000i[0i[i i 000i0i[i i 00i0ii[i i 000i`0i[i i 000ic0i[i i 00i0ii[i i 000ii0i[i i 000ih0i[i i 000i0i[i i 00i0ii[i i 000io0i[i i 000ir0i[i i 000iu0i[i i I"Ơ; TI"Ơ; T0i0i[i i I"ơ; TI"ơ; Ti0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 000i0i[i i 00i0ii[i i 000i0i[i i 000i0i[i i 00i0ii[i i 000i0i[i i I"Ư; TI"Ư; T0i0i[i i I"ư; TI"ư; Ti0ii[i i 000i0i[i i 000i0i[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 00i0ii[i i 0I"DŽ; T0iii[i i 0I"Dž; Tii0i[i i 0I"dž; Ti0ii[i i 0I"LJ; T0iii[i i 0I"Lj; Tii0i[i i 0I"lj; Ti0ii[i i 0I"NJ; T0iii[i i 0I"Nj; Tii0i[i i 0I"nj; Ti0ii[i i I"Ǎ; TI"Ǎ; T0i0i[i i I"ǎ; TI"ǎ; Ti0ii[i i I"Ǐ; TI"Ǐ; T0i0i[i i I"ǐ; TI"ǐ; Ti0ii[i i I"Ǒ; TI"Ǒ; T0i0i[i i I"ǒ; TI"ǒ; Ti0ii[i i I"Ǔ; TI"Ǔ; T0i0i[i i I"ǔ; TI"ǔ; Ti0ii[i i I" Ǖ; TI" Ǖ; T0i0i[i i I" ǖ; TI" ǖ; Ti0ii[i i I" Ǘ; TI" Ǘ; T0i0i[i i I" ǘ; TI" ǘ; Ti0ii[i i I" Ǚ; TI" Ǚ; T0i0i[i i I" ǚ; TI" ǚ; Ti0ii[i i I" Ǜ; TI" Ǜ; T0i0i[i i I" ǜ; TI" ǜ; Ti0ii[i i 00i0ii[i i I" Ǟ; TI" Ǟ; T0i0i[i i I" ǟ; TI" ǟ; Ti0ii[i i I" Ǡ; TI" Ǡ; T0i0i[i i I" ǡ; TI" ǡ; Ti0ii[i i I" Ǣ; TI" Ǣ; T0i0i[i i I" ǣ; TI" ǣ; Ti0ii[i i 000i0i[i i 00i0ii[i i I"Ǧ; TI"Ǧ; T0i0i[i i I"ǧ; TI"ǧ; Ti0ii[i i I"Ǩ; TI"Ǩ; T0i0i[i i I"ǩ; TI"ǩ; Ti0ii[i i I"Ǫ; TI"Ǫ; T0i0i[i i I"ǫ; TI"ǫ; Ti0ii[i i I" Ǭ; TI" Ǭ; T0i0i[i i I" ǭ; TI" ǭ; Ti0ii[i i I" Ǯ; TI" Ǯ; T0i0i[i i I" ǯ; TI" ǯ; Ti0ii[i i I"ǰ; TI"ǰ; T000i[i i 0I"DZ; T0iii[i i 0I"Dz; Tii0i[i i 0I"dz; Ti0ii[i i I"Ǵ; TI"Ǵ; T0i0i[i i I"ǵ; TI"ǵ; Ti0ii[i i 000i0i[i i 000i0i[i i I"Ǹ; TI"Ǹ; T0i0i[i i I"ǹ; TI"ǹ; Ti0ii[i i I" Ǻ; TI" Ǻ; T0i0i[i i I" ǻ; TI" ǻ; Ti0ii[i i I" Ǽ; TI" Ǽ; T0i0i[i i I" ǽ; TI" ǽ; Ti0ii[i i I" Ǿ; TI" Ǿ; T0i0i[i i I" ǿ; TI" ǿ; Ti0ii [i i I"Ȁ; TI"Ȁ; T0i0i[i i I"ȁ; TI"ȁ; Ti 0i i[i i I"Ȃ; TI"Ȃ; T0i0i[i i I"ȃ; TI"ȃ; Ti0ii[i i I"Ȅ; TI"Ȅ; T0i0i[i i I"ȅ; TI"ȅ; Ti0ii[i i I"Ȇ; TI"Ȇ; T0i0i[i i I"ȇ; TI"ȇ; Ti0ii[i i I"Ȉ; TI"Ȉ; T0i 0i [i i I"ȉ; TI"ȉ; Ti0ii
[i i I"Ȋ; TI"Ȋ; T0i0i[i i I"ȋ; TI"ȋ; Ti
0i
i[i i I"Ȍ; TI"Ȍ; T0i
0i
[i i I"ȍ; TI"ȍ; Ti0ii[i i I"Ȏ; TI"Ȏ; T0i0i[i i I"ȏ; TI"ȏ; Ti0ii[i i I"Ȑ; TI"Ȑ; T0i0i[i i I"ȑ; TI"ȑ; Ti0ii[i i I"Ȓ; TI"Ȓ; T0i0i[i i I"ȓ; TI"ȓ; Ti0ii[i i I"Ȕ; TI"Ȕ; T0i0i[i i I"ȕ; TI"ȕ; Ti0ii[i i I"Ȗ; TI"Ȗ; T0i0i[i i I"ȗ; TI"ȗ; Ti0ii[i i I"Ș; TI"Ș; T0i0i[i i I"ș; TI"ș; Ti0ii[i i I"Ț; TI"Ț; T0i0i[i i I"ț; TI"ț; Ti0ii[i i 000i0i[i i 00i0ii[i i I"Ȟ; TI"Ȟ; T0i0i[i i I"ȟ; TI"ȟ; Ti0ii"[i i 000i#0i#[i i 00i"0i"i$[i i 000i%0i%[i i 00i$0i$i&[i i I"Ȧ; TI"Ȧ; T0i'0i'[i i I"ȧ; TI"ȧ; Ti&0i&i([i i I"Ȩ; TI"Ȩ; T0i)0i)[i i I"ȩ; TI"ȩ; Ti(0i(i*[i i I" Ȫ; TI" Ȫ; T0i+0i+[i i I" ȫ; TI" ȫ; Ti*0i*i,[i i I" Ȭ; TI" Ȭ; T0i-0i-[i i I" ȭ; TI" ȭ; Ti,0i,i.[i i I"Ȯ; TI"Ȯ; T0i/0i/[i i I"ȯ; TI"ȯ; Ti.0i.i0[i i I" Ȱ; TI" Ȱ; T0i10i1[i i I" ȱ; TI" ȱ; Ti00i0i2[i i I"Ȳ; TI"Ȳ; T0i30i3[i i I"ȳ; TI"ȳ; Ti20i2iS[i i 00i0iiT[i i 00i0iiV[i i 00i0iiW[i i 00i0iiY[i i 00i0ii[[i i 00i0ii`[i i 00i0iic[i i 00i0iih[i i 00i0iii[i i 00i0iio[i i 00i0iir[i i 00i0iiu[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 0I"h; T000i[i i 0I"ɦ; T000i[i i 0I"j; T000i[i i 0I"r; T000i[i i 0I"ɹ; T000i[i i 0I"ɻ; T000i[i i 0I"ʁ; T000i[i i 0I"w; T000i[i i 0I"y; T000i[i i 0I" ̆; T000i[i i 0I" ̇; T000i[i i 0I" ̊; T000i[i i 0I" ̨; T000i[i i 0I" ̃; T000i[i i 0I" ̋; T000i[i i 0I"ɣ; T000i[i i 0I"l; T000i[i i 0I"s; T000i[i i 0I"x; T000i[i i 0I"ʕ; T000i [ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i [ii 00000i
[ii 00000i[ii 00000i[ii 00000i
[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i [ii 00000i![ii 00000i"[ii 00000i#[ii 00000i$[ii 00000i%[ii 00000i&[ii 00000i'[ii 00000i([ii 00000i)[ii 00000i*[ii 00000i+[ii 00000i,[ii 00000i-[ii 00000i.[ii 00000i/[ii 00000i0[ii 00000i1[ii 00000i2[ii 00000i3[ii 00000i4[ii 00000i5[ii 00000i6[ii 00000i7[ii 00000i8[ii 00000i9[ii 00000i:[ii 00000i;[ii 00000i<[ii 00000i=[ii 00000i>[ii 00000i?[ii 00000i@[iiI"̀; TI"̀; T000iA[iiI"́; TI"́; T000iB[ii 00000iC[iiI"̓; TI"̓; T000iD[iiI" ̈́; TI" ̈́; T000iE[ii 00i0iiF[ii 00000iG[ii 00000iH[ii 00000iI[ii 00000iJ[ii 00000iK[ii 00000iL[ii 00000iM[ii 00000iN[ii 00000i`[ii 00000ia[ii 00000ib[ii 00000it[i iI"ʹ; TI"ʹ; T000iz[i i 0I" ͅ; T000i~[i iI";; TI";; T000i[i i 0I" ́; T000i[i i I" ΅; TI" ΅; T000i[i i I" Ά; TI" Ά; T0i0i[i iI"·; TI"·; T000i[i i I" Έ; TI" Έ; T0i0i[i i I" Ή; TI" Ή; T0i0i[i i I" Ί; TI" Ί; T0i0i[i i I" Ό; TI" Ό; T0i0i[i i I" Ύ; TI" Ύ; T0i0i[i i I" Ώ; TI" Ώ; T0i0i[i i I" ΐ; TI" ΐ; T000i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i 000i0i[i i I" Ϊ; TI" Ϊ; T0i0i[i i I" Ϋ; TI" Ϋ; T0i0i[i i I" ά; TI" ά; Ti0ii[i i I" έ; TI" έ; Ti0ii[i i I" ή; TI" ή; Ti0ii[i i I" ί; TI" ί; Ti0ii[i i I" ΰ; TI" ΰ; T000i[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i 00i0ii[i i I" ϊ; TI" ϊ; Ti0ii[i i I" ϋ; TI" ϋ; Ti0ii[i i I" ό; TI" ό; Ti0ii[i i I" ύ; TI" ύ; Ti0ii[i i I" ώ; TI" ώ; Ti0ii[i i 0I"β; Ti0ii[i i 0I"θ; Ti0ii[i i 0I"Υ; T000i[i i I" ϓ; TI" ϓ; T000i[i i I" ϔ; TI" ϔ; T000i[i i 0I"φ; Ti0ii[i i 0I"π; Ti0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 0I"κ; Ti0ii[i i 0I"ρ; Ti0ii[i i 0I"ς; Ti0ii [i i I" Ѐ; TI" Ѐ; T0iP0i[i i I" Ё; TI" Ё; T0iQ0i[i i 000iR0i[i i I" Ѓ; TI" Ѓ; T0iS0i[i i 000iT0i[i i 000iU0i[i i 000iV0i[i i I" Ї; TI" Ї; T0iW0i[i i 000iX0i [i i 000iY0i
[i i 000iZ0i[i i 000i[0i[i i I" Ќ; TI" Ќ; T0i\0i
[i i I" Ѝ; TI" Ѝ; T0i]0i[i i I" Ў; TI" Ў; T0i^0i[i i 000i_0i[i i 000i00i[i i 000i10i[i i 000i20i[i i 000i30i[i i 000i40i[i i 000i50i[i i 000i60i[i i 000i70i[i i 000i80i[i i I" Й; TI" Й; T0i90i[i i 000i:0i[i i 000i;0i[i i 000i<0i[i i 000i=0i[i i 000i>0i[i i 000i?0i [i i 000i@0i![i i 000iA0i"[i i 000iB0i#[i i 000iC0i$[i i 000iD0i%[i i 000iE0i&[i i 000iF0i'[i i 000iG0i([i i 000iH0i)[i i 000iI0i*[i i 000iJ0i+[i i 000iK0i,[i i 000iL0i-[i i 000iM0i.[i i 000iN0i/[i i 000iO0i0[i i 00i0ii1[i i 00i0ii2[i i 00i0ii3[i i 00i0ii4[i i 00i0ii5[i i 00i0ii6[i i 00i0ii7[i i 00i0ii8[i i 00i0ii9[i i I" й; TI" й; Ti0ii:[i i 00i0ii;[i i 00i0ii<[i i 00i0ii=[i i 00i0ii>[i i 00i0ii?[i i 00i0ii@[i i 00i 0i iA[i i 00i!0i!iB[i i 00i"0i"iC[i i 00i#0i#iD[i i 00i$0i$iE[i i 00i%0i%iF[i i 00i&0i&iG[i i 00i'0i'iH[i i 00i(0i(iI[i i 00i)0i)iJ[i i 00i*0i*iK[i i 00i+0i+iL[i i 00i,0i,iM[i i 00i-0i-iN[i i 00i.0i.iO[i i 00i/0i/iP[i i I" ѐ; TI" ѐ; Ti 0i iQ[i i I" ё; TI" ё; Ti0iiR[i i 00i0iiS[i i I" ѓ; TI" ѓ; Ti0iiT[i i 00i0iiU[i i 00i0iiV[i i 00i0iiW[i i I" ї; TI" ї; Ti0iiX[i i 00i0iiY[i i 00i 0i iZ[i i 00i
0i
i[[i i 00i0ii\[i i I" ќ; TI" ќ; Ti0ii][i i I" ѝ; TI" ѝ; Ti
0i
i^[i i I" ў; TI" ў; Ti0ii_[i i 00i0ii`[i i 000ia0ia[i i 00i`0i`ib[i i 000ic0ic[i i 00ib0ibid[i i 000ie0ie[i i 00id0idif[i i 000ig0ig[i i 00if0ifih[i i 000ii0ii[i i 00ih0ihij[i i 000ik0ik[i i 00ij0ijil[i i 000im0im[i i 00il0ilin[i i 000io0io[i i 00in0inip[i i 000iq0iq[i i 00ip0ipir[i i 000is0is[i i 00ir0irit[i i 000iu0iu[i i 00it0itiv[i i I" Ѷ; TI" Ѷ; T0iw0iw[i i I" ѷ; TI" ѷ; Tiv0ivix[i i 000iy0iy[i i 00ix0ixiz[i i 000i{0i{[i i 00iz0izi|[i i 000i}0i}[i i 00i|0i|i~[i i 000i0i[i i 00i~0i~i[i i 000i0i[i i 00i0ii[ii 00000i[ii 00000i[ii 00000i[ii 00000i[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i I" Ӂ; TI" Ӂ; T0i0i[i i I" ӂ; TI" ӂ; Ti0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i 000i0i[i i 00i0ii[i i I" Ӑ; TI" Ӑ; T0i0i[i i I" ӑ; TI" ӑ; Ti0ii[i i I" Ӓ; TI" Ӓ; T0i0i[i i I" ӓ; TI" ӓ; Ti0ii[i i 000i0i[i i 00i0ii[i i I" Ӗ; TI" Ӗ; T0i0i[i i I" ӗ; TI" ӗ; Ti0ii[i i 000i0i[i i 00i0ii[i i I" Ӛ; TI" Ӛ; T0i0i[i i I" ӛ; TI" ӛ; Ti0ii[i i I" Ӝ; TI" Ӝ; T0i0i[i i I" ӝ; TI" ӝ; Ti0ii[i i I" Ӟ; TI" Ӟ; T0i0i[i i I" ӟ; TI" ӟ; Ti0ii[i i 000i0i[i i 00i0ii[i i I" Ӣ; TI" Ӣ; T0i0i[i i I" ӣ; TI" ӣ; Ti0ii[i i I" Ӥ; TI" Ӥ; T0i0i[i i I" ӥ; TI" ӥ; Ti0ii[i i I" Ӧ; TI" Ӧ; T0i0i[i i I" ӧ; TI" ӧ; Ti0ii[i i 000i0i[i i 00i0ii[i i I" Ӫ; TI" Ӫ; T0i0i[i i I" ӫ; TI" ӫ; Ti0ii[i i I" Ӭ; TI" Ӭ; T0i0i[i i I" ӭ; TI" ӭ; Ti0ii[i i I" Ӯ; TI" Ӯ; T0i0i[i i I" ӯ; TI" ӯ; Ti0ii[i i I" Ӱ; TI" Ӱ; T0i0i[i i I" ӱ; TI" ӱ; Ti0ii[i i I" Ӳ; TI" Ӳ; T0i0i[i i I" ӳ; TI" ӳ; Ti0ii[i i I" Ӵ; TI" Ӵ; T0i0i[i i I" ӵ; TI" ӵ; Ti0ii[i i I" Ӹ; TI" Ӹ; T0i0i[i i I" ӹ; TI" ӹ; Ti0ii1[i i 000ia0i2[i i 000ib0i3[i i 000ic0i4[i i 000id0i5[i i 000ie0i6[i i 000if0i7[i i 000ig0i8[i i 000ih0i9[i i 000ii0i:[i i 000ij0i;[i i 000ik0i<[i i 000il0i=[i i 000im0i>[i i 000in0i?[i i 000io0i@[i i 000ip0iA[i i 000iq0iB[i i 000ir0iC[i i 000is0iD[i i 000it0iE[i i 000iu0iF[i i 000iv0iG[i i 000iw0iH[i i 000ix0iI[i i 000iy0iJ[i i 000iz0iK[i i 000i{0iL[i i 000i|0iM[i i 000i}0iN[i i 000i~0iO[i i 000i0iP[i i 000i0iQ[i i 000i0iR[i i 000i0iS[i i 000i0iT[i i 000i0iU[i i 000i0iV[i i 000i0ia[i i 00i10i1ib[i i 00i20i2ic[i i 00i30i3id[i i 00i40i4ie[i i 00i50i5if[i i 00i60i6ig[i i 00i70i7ih[i i 00i80i8ii[i i 00i90i9ij[i i 00i:0i:ik[i i 00i;0i;il[i i 00i<0i<im[i i 00i=0i=in[i i 00i>0i>io[i i 00i?0i?ip[i i 00i@0i@iq[i i 00iA0iAir[i i 00iB0iBis[i i 00iC0iCit[i i 00iD0iDiu[i i 00iE0iEiv[i i 00iF0iFiw[i i 00iG0iGix[i i 00iH0iHiy[i i 00iI0iIiz[i i 00iJ0iJi{[i i 00iK0iKi|[i i 00iL0iLi}[i i 00iM0iMi~[i i 00iN0iNi[i i 00iO0iOi[i i 00iP0iPi[i i 00iQ0iQi[i i 00iR0iRi[i i 00iS0iSi[i i 00iT0iTi[i i 00iU0iUi[i i 00iV0iVi[i i 0I" եւ; T000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i[ii 00000i"[i i I" آ; TI" آ; T000i#[i i I" أ; TI" أ; T000i$[i i I" ؤ; TI" ؤ; T000i%[i i I" إ; TI" إ; T000i&[i i I" ئ; TI" ئ; T000iK[i i 00000iL[i!i 00000iM[i"i 00000iN[i#i 00000iO[i$i 00000iP[i%i 00000iQ[i&i