url_canonicalize 0.2.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,22 +4,23 @@ module URLCanonicalize
4
4
  # Manage the URL into a URI with local exception handling
5
5
  class URI
6
6
  class << self
7
+ VALID_CLASSES = [::URI::HTTP, ::URI::HTTPS].freeze
8
+ COLON = ':'
9
+
7
10
  def parse(url)
8
11
  uri = ::URI.parse decorate(url)
9
- uri if valid? uri
12
+ validate! uri
13
+ uri
10
14
  rescue ::URI::InvalidURIError => e
11
- new_exception = URLCanonicalize::Exception::URI.new("#{e.class}: #{e.message}")
12
- new_exception.set_backtrace e.backtrace
13
- raise new_exception
15
+ raise URLCanonicalize::Exception::URI, "#{e.class}: #{e.message}" # the original error becomes the cause
14
16
  end
15
17
 
16
18
  private
17
19
 
18
- def valid?(uri)
20
+ def validate!(uri)
19
21
  raise URLCanonicalize::Exception::URI, "#{uri} must be http or https" unless VALID_CLASSES.include?(uri.class)
20
22
  raise URLCanonicalize::Exception::URI, "Missing host name in #{uri}" unless uri.host
21
-
22
- true
23
+ raise URLCanonicalize::Exception::URI, "Empty host name in #{uri}" if uri.host.empty?
23
24
  end
24
25
 
25
26
  def decorate(url)
@@ -27,9 +28,6 @@ module URLCanonicalize
27
28
 
28
29
  "http://#{url}" # Add protocol if we just receive a host name
29
30
  end
30
-
31
- VALID_CLASSES = [::URI::HTTP, ::URI::HTTPS].freeze
32
- COLON = ':'
33
31
  end
34
32
  end
35
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module URLCanonicalize
4
- VERSION = '0.2.1'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -4,25 +4,31 @@ require 'uri'
4
4
  require 'addressable/uri'
5
5
  require 'net/http'
6
6
  require 'nokogiri'
7
+ require 'timeout'
7
8
 
8
9
  autoload :OpenSSL, 'openssl'
9
10
 
10
11
  # Core methods
11
12
  module URLCanonicalize
13
+ autoload :BoundedBody, 'url_canonicalize/bounded_body'
14
+ autoload :Destination, 'url_canonicalize/destination'
12
15
  autoload :Exception, 'url_canonicalize/exception'
13
16
  autoload :HTTP, 'url_canonicalize/http'
17
+ autoload :LinkHeader, 'url_canonicalize/link_header'
18
+ autoload :MediaType, 'url_canonicalize/media_type'
19
+ autoload :Options, 'url_canonicalize/options'
14
20
  autoload :Request, 'url_canonicalize/request'
15
21
  autoload :Response, 'url_canonicalize/response'
16
22
  autoload :URI, 'url_canonicalize/uri'
17
23
  autoload :VERSION, 'url_canonicalize/version'
18
24
 
19
25
  class << self
20
- def canonicalize(url)
21
- fetch(url).url
26
+ def canonicalize(url, **options)
27
+ fetch(url, **options).url
22
28
  end
23
29
 
24
- def fetch(url)
25
- URLCanonicalize::HTTP.new(url).fetch
30
+ def fetch(url, **options)
31
+ URLCanonicalize::HTTP.new(url, **options).fetch
26
32
  end
27
33
  end
28
34
  end
@@ -30,4 +36,3 @@ end
30
36
  require 'monkey_patches/uri'
31
37
  require 'monkey_patches/string'
32
38
  require 'monkey_patches/addressable/uri'
33
- require 'English' # Needed for $LAST_MATCH_INFO
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url_canonicalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Sayers
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-02-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: addressable
@@ -46,38 +45,35 @@ executables: []
46
45
  extensions: []
47
46
  extra_rdoc_files: []
48
47
  files:
49
- - ".codeclimate.yml"
50
- - ".gitignore"
51
- - ".hound.yml"
52
- - ".rspec"
53
- - ".rubocop.yml"
54
- - ".ruby-gemset"
55
- - ".travis.yml"
56
48
  - CHANGELOG.md
57
- - Gemfile
58
- - Gemfile.lock
59
- - Guardfile
60
49
  - LICENSE
61
50
  - README.md
62
- - Rakefile
63
- - circle.yml
51
+ - SECURITY.md
64
52
  - lib/monkey_patches/addressable/uri.rb
65
53
  - lib/monkey_patches/string.rb
66
54
  - lib/monkey_patches/uri.rb
67
55
  - lib/url_canonicalize.rb
56
+ - lib/url_canonicalize/bounded_body.rb
57
+ - lib/url_canonicalize/destination.rb
68
58
  - lib/url_canonicalize/exception.rb
69
59
  - lib/url_canonicalize/http.rb
60
+ - lib/url_canonicalize/link_header.rb
61
+ - lib/url_canonicalize/media_type.rb
62
+ - lib/url_canonicalize/options.rb
70
63
  - lib/url_canonicalize/request.rb
71
64
  - lib/url_canonicalize/response.rb
72
65
  - lib/url_canonicalize/uri.rb
73
66
  - lib/url_canonicalize/version.rb
74
- - url_canonicalize.gemspec
75
67
  homepage: https://github.com/dominicsayers/url_canonicalize
76
68
  licenses:
77
69
  - MIT
78
70
  metadata:
71
+ bug_tracker_uri: https://github.com/dominicsayers/url_canonicalize/issues
72
+ changelog_uri: https://github.com/dominicsayers/url_canonicalize/blob/main/CHANGELOG.md
73
+ documentation_uri: https://www.rubydoc.info/gems/url_canonicalize
74
+ homepage_uri: https://github.com/dominicsayers/url_canonicalize
75
+ source_code_uri: https://github.com/dominicsayers/url_canonicalize
79
76
  rubygems_mfa_required: 'true'
80
- post_install_message:
81
77
  rdoc_options: []
82
78
  require_paths:
83
79
  - lib
@@ -85,15 +81,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
81
  requirements:
86
82
  - - ">="
87
83
  - !ruby/object:Gem::Version
88
- version: 2.6.0
84
+ version: 3.1.0
89
85
  required_rubygems_version: !ruby/object:Gem::Requirement
90
86
  requirements:
91
87
  - - ">="
92
88
  - !ruby/object:Gem::Version
93
89
  version: '0'
94
90
  requirements: []
95
- rubygems_version: 3.3.6
96
- signing_key:
91
+ rubygems_version: 4.0.16
97
92
  specification_version: 4
98
93
  summary: Finds the canonical version of a URL
99
94
  test_files: []
data/.codeclimate.yml DELETED
@@ -1,25 +0,0 @@
1
- ---
2
- engines:
3
- duplication:
4
- enabled: true
5
- config:
6
- languages:
7
- - ruby
8
- - javascript
9
- - python
10
- - php
11
- fixme:
12
- enabled: true
13
- rubocop:
14
- enabled: true
15
- ratings:
16
- paths:
17
- - "**.inc"
18
- - "**.js"
19
- - "**.jsx"
20
- - "**.module"
21
- - "**.php"
22
- - "**.py"
23
- - "**.rb"
24
- exclude_paths:
25
- - spec/
data/.gitignore DELETED
@@ -1,51 +0,0 @@
1
- *.local
2
- *.gem
3
- *.rbc
4
- /.config
5
- /coverage/
6
- /InstalledFiles
7
- /pkg/
8
- /spec/reports/
9
- /spec/examples.txt
10
- /test/tmp/
11
- /test/version_tmp/
12
- /tmp/
13
-
14
- # Used by dotenv library to load environment variables.
15
- # .env
16
-
17
- ## Specific to RubyMotion:
18
- .dat*
19
- .repl_history
20
- build/
21
- *.bridgesupport
22
- build-iPhoneOS/
23
- build-iPhoneSimulator/
24
-
25
- ## Specific to RubyMotion (use of CocoaPods):
26
- #
27
- # We recommend against adding the Pods directory to your .gitignore. However
28
- # you should judge for yourself, the pros and cons are mentioned at:
29
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
- #
31
- # vendor/Pods/
32
-
33
- ## Documentation cache and generated files:
34
- /.yardoc/
35
- /_yardoc/
36
- /doc/
37
- /rdoc/
38
-
39
- ## Environment normalization:
40
- /.bundle/
41
- /vendor/bundle
42
- /lib/bundler/man/
43
-
44
- # for a library or gem, you might want to ignore these files since the code is
45
- # intended to run in multiple environments; otherwise, check them in:
46
- # Gemfile.lock
47
- .ruby-version
48
- .ruby-gemset
49
-
50
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
- .rvmrc
data/.hound.yml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- ruby:
3
- enabled: true
4
- config_file: .rubocop.yml
data/.rspec DELETED
@@ -1,5 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --profile
4
- --format progress
5
- --format RspecJunitFormatter --out <%= ENV.fetch('CIRCLE_TEST_REPORTS', 'tmp') %>/rspec/rspec.xml
data/.rubocop.yml DELETED
@@ -1,61 +0,0 @@
1
- ---
2
- AllCops:
3
- DisplayStyleGuide: true
4
- DisplayCopNames: true
5
- TargetRubyVersion: 2.6
6
- NewCops: enable
7
-
8
- Layout/DotPosition:
9
- Description: 'Checks the position of the dot in multi-line method calls.'
10
- EnforcedStyle: leading
11
- Enabled: true
12
-
13
- Layout/ExtraSpacing:
14
- Description: 'Do not use unnecessary spacing.'
15
- Enabled: true
16
-
17
- Layout/LineLength:
18
- Max: 120
19
- Exclude:
20
- - spec/**/*
21
-
22
- Lint/LiteralInInterpolation:
23
- Description: 'Avoid interpolating literals in strings'
24
- AutoCorrect: true
25
-
26
- Metrics/BlockLength:
27
- Exclude:
28
- - spec/**/*
29
-
30
- Metrics/ClassLength:
31
- CountComments: false # count full line comments?
32
- Max: 200
33
-
34
- Metrics/MethodLength:
35
- Max: 12
36
-
37
- Naming/FileName:
38
- Description: 'Use snake_case for source file names.'
39
- Enabled: true
40
-
41
- Style/ClassAndModuleChildren:
42
- Description: 'Checks style of children classes and modules.'
43
- EnforcedStyle: nested
44
- Enabled: true
45
-
46
- Style/Documentation:
47
- Description: 'Document classes and non-namespace modules.'
48
- Enabled: false
49
-
50
- Style/StringLiterals:
51
- EnforcedStyle: single_quotes
52
- Enabled: true
53
-
54
- Style/SymbolArray:
55
- Description: 'Use %i or %I for arrays of symbols.'
56
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-i'
57
- Enabled: false # Only available in Ruby 2.0+
58
-
59
- Style/TrailingCommaInArguments:
60
- EnforcedStyleForMultiline: no_comma
61
- Enabled: true
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- url_canonicalize
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- ---
2
- language: ruby
3
- rvm:
4
- - 2.6
5
- - 2.7
6
- - 3.0
7
- - 3.1
8
- script:
9
- - rspec
data/Gemfile DELETED
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec
6
-
7
- group :static_code_analysis do
8
- gem 'rubocop', require: false
9
- gem 'rubocop-rspec', require: false
10
- end
11
-
12
- group :test do
13
- gem 'coveralls', require: false
14
- gem 'rspec'
15
- gem 'rspec_junit_formatter'
16
- gem 'simplecov', '~> 0.13'
17
- gem 'webmock'
18
- end
19
-
20
- group :build do
21
- gem 'gem-release', require: false
22
- end
data/Gemfile.lock DELETED
@@ -1,102 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- url_canonicalize (0.2.1)
5
- addressable (~> 2)
6
- nokogiri (>= 1.13)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.8.0)
12
- public_suffix (>= 2.0.2, < 5.0)
13
- ast (2.4.2)
14
- coveralls (0.7.2)
15
- multi_json (~> 1.3)
16
- rest-client (= 1.6.7)
17
- simplecov (>= 0.7)
18
- term-ansicolor (= 1.2.2)
19
- thor (= 0.18.1)
20
- crack (0.4.5)
21
- rexml
22
- diff-lcs (1.5.0)
23
- docile (1.4.0)
24
- gem-release (2.2.2)
25
- hashdiff (1.0.1)
26
- mime-types (3.4.1)
27
- mime-types-data (~> 3.2015)
28
- mime-types-data (3.2022.0105)
29
- multi_json (1.15.0)
30
- nokogiri (1.13.1-x86_64-linux)
31
- racc (~> 1.4)
32
- parallel (1.21.0)
33
- parser (3.1.0.0)
34
- ast (~> 2.4.1)
35
- public_suffix (4.0.6)
36
- racc (1.6.0)
37
- rainbow (3.1.1)
38
- regexp_parser (2.2.0)
39
- rest-client (1.6.7)
40
- mime-types (>= 1.16)
41
- rexml (3.2.5)
42
- rspec (3.10.0)
43
- rspec-core (~> 3.10.0)
44
- rspec-expectations (~> 3.10.0)
45
- rspec-mocks (~> 3.10.0)
46
- rspec-core (3.10.2)
47
- rspec-support (~> 3.10.0)
48
- rspec-expectations (3.10.2)
49
- diff-lcs (>= 1.2.0, < 2.0)
50
- rspec-support (~> 3.10.0)
51
- rspec-mocks (3.10.3)
52
- diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.10.0)
54
- rspec-support (3.10.3)
55
- rspec_junit_formatter (0.5.1)
56
- rspec-core (>= 2, < 4, != 2.12.0)
57
- rubocop (1.25.0)
58
- parallel (~> 1.10)
59
- parser (>= 3.1.0.0)
60
- rainbow (>= 2.2.2, < 4.0)
61
- regexp_parser (>= 1.8, < 3.0)
62
- rexml
63
- rubocop-ast (>= 1.15.1, < 2.0)
64
- ruby-progressbar (~> 1.7)
65
- unicode-display_width (>= 1.4.0, < 3.0)
66
- rubocop-ast (1.15.1)
67
- parser (>= 3.0.1.1)
68
- rubocop-rspec (2.8.0)
69
- rubocop (~> 1.19)
70
- ruby-progressbar (1.11.0)
71
- simplecov (0.21.2)
72
- docile (~> 1.1)
73
- simplecov-html (~> 0.11)
74
- simplecov_json_formatter (~> 0.1)
75
- simplecov-html (0.12.3)
76
- simplecov_json_formatter (0.1.3)
77
- term-ansicolor (1.2.2)
78
- tins (~> 0.8)
79
- thor (0.18.1)
80
- tins (0.13.2)
81
- unicode-display_width (2.1.0)
82
- webmock (3.14.0)
83
- addressable (>= 2.8.0)
84
- crack (>= 0.3.2)
85
- hashdiff (>= 0.4.0, < 2.0.0)
86
-
87
- PLATFORMS
88
- x86_64-linux
89
-
90
- DEPENDENCIES
91
- coveralls
92
- gem-release
93
- rspec
94
- rspec_junit_formatter
95
- rubocop
96
- rubocop-rspec
97
- simplecov (~> 0.13)
98
- url_canonicalize!
99
- webmock
100
-
101
- BUNDLED WITH
102
- 2.3.6
data/Guardfile DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- guard :rubocop do
4
- watch(/.+\.rb$/)
5
- watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
6
- end
7
-
8
- guard(
9
- :rspec,
10
- all_after_pass: false,
11
- all_on_start: false,
12
- cmd: 'NO_SIMPLECOV=true bundle exec rspec --fail-fast --format documentation'
13
- ) do
14
- watch(%r{spec/.+_spec\.rb$})
15
- watch(%r{lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
16
- watch('spec/spec_helper.rb') { 'spec' }
17
- watch(%r{^spec/support/.+\.rb$}) { 'spec' }
18
- end
data/Rakefile DELETED
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
data/circle.yml DELETED
@@ -1,29 +0,0 @@
1
- version: 2.1
2
- orbs:
3
- ruby: circleci/ruby@1.1
4
- jobs:
5
- check_and_test:
6
- parameters:
7
- ruby-version:
8
- type: string
9
- docker:
10
- - image: cimg/ruby:<< parameters.ruby-version >>
11
- parallelism: 3
12
- steps:
13
- - checkout
14
- - ruby/install-deps
15
- - run:
16
- name: Run static code analysis
17
- command: bundle exec rubocop
18
- - run:
19
- name: Run tests
20
- command: bundle exec rspec
21
- workflows:
22
- version: 2
23
- test:
24
- jobs:
25
- - check_and_test:
26
- # cribbed from http://mikebian.co/running-tests-against-multiple-ruby-versions-using-circleci/
27
- matrix:
28
- parameters:
29
- ruby-version: ["2.6", "2.7", "3.0", "3.1"]
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'url_canonicalize/version'
6
-
7
- Gem::Specification.new do |s|
8
- s.name = 'url_canonicalize'
9
- s.version = URLCanonicalize::VERSION
10
- s.authors = ['Dominic Sayers']
11
- s.email = ['dominic@sayers.cc']
12
- s.summary = 'Finds the canonical version of a URL'
13
- s.description = 'Rubygem that finds the canonical version of a URL by '\
14
- 'providing #canonicalize methods for the String, URI::HTTP'\
15
- ', URI::HTTPS and Addressable::URI classes'
16
- s.homepage = 'https://github.com/dominicsayers/url_canonicalize'
17
- s.license = 'MIT'
18
-
19
- s.required_ruby_version = '>= 2.6.0'
20
-
21
- s.files = `git ls-files`.split($RS).grep_v(%r{^spec/})
22
-
23
- s.test_files = []
24
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
- s.require_paths = ['lib']
26
-
27
- s.add_runtime_dependency 'addressable', '~> 2' # To normalize URLs
28
- s.add_runtime_dependency 'nokogiri', '>= 1.13' # To look for <link rel="canonical" ...> in HTML
29
- s.metadata['rubygems_mfa_required'] = 'true'
30
- end