public_suffix 1.5.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5e75fe3c5d642adeeae60366174f25b99844b90
4
- data.tar.gz: 1dc35267a417747ab37e1997434d5e219839a391
3
+ metadata.gz: eaa67d1cb0c7a21070e9b0bc56d3f83950efddb3
4
+ data.tar.gz: 6c15669d468bf25585e7381127adc4670b147879
5
5
  SHA512:
6
- metadata.gz: 05477a5b192b451131723a039815127c0c12cc89b2c911f3f162e1fc20a2a596cf7639d46f521d1a17fb7f1db7a9ad29d2181809e952a581d68f530369cdff54
7
- data.tar.gz: 16bf8bf394f1efca171596991c4d3039a09b658932dc7c45c00277b0fb482a917b203a53f640d83185497f2bb6e535554f69333be777d36807e1cd7699e5d98c
6
+ metadata.gz: 7ad8bbd99caed951de6db31c58e6597e928af763aadb92a284533c2f64e9c6e6652a43cb2f890839ca052a7358d46fd35f87f7402334f3776955a3abdea4f609
7
+ data.tar.gz: c59285a5c3c31f617f3e935202a7058d733629fb77fe1b3b9797e554de837810986b26a3e00f328a9d1511a00836a0de696d6bad1df899bf606a7e28c573988b
@@ -0,0 +1,8 @@
1
+ inherit_from:
2
+ - .rubocop_defaults.yml
3
+
4
+ Style/ClassAndModuleChildren:
5
+ Exclude:
6
+ - 'spec/**/*_spec.rb'
7
+ - 'test/**/*_test.rb'
8
+
@@ -0,0 +1,127 @@
1
+ AllCops:
2
+ Exclude:
3
+ # Exclude .gemspec files because they are generally auto-generated
4
+ - '*.gemspec'
5
+ # Exclude vendored folders
6
+ - 'tmp/**/*'
7
+ - 'vendor/**/*'
8
+
9
+ Lint/AmbiguousRegexpLiteral:
10
+ Enabled: false
11
+
12
+ # [codesmell]
13
+ Metrics/AbcSize:
14
+ Enabled: false
15
+ Exclude:
16
+ - 'spec/**/*_spec.rb'
17
+ - 'test/**/*_test.rb'
18
+
19
+ # [codesmell]
20
+ Metrics/ClassLength:
21
+ Exclude:
22
+ - 'spec/**/*_spec.rb'
23
+ - 'test/**/*_test.rb'
24
+
25
+ # [codesmell]
26
+ Metrics/MethodLength:
27
+ Exclude:
28
+ - 'spec/**/*_spec.rb'
29
+ - 'test/**/*_test.rb'
30
+ Max: 15
31
+
32
+ # [codesmell]
33
+ Metrics/LineLength:
34
+ Enabled: false
35
+ Exclude:
36
+ - 'spec/**/*_spec.rb'
37
+ - 'test/**/*_test.rb'
38
+ Max: 100
39
+
40
+ # Do not use "and" or "or" in conditionals, but for readability we can use it
41
+ # to chain executions. Just beware of operator order.
42
+ Style/AndOr:
43
+ EnforcedStyle: conditionals
44
+
45
+ Style/Documentation:
46
+ Exclude:
47
+ - 'spec/**/*'
48
+ - 'test/**/*'
49
+
50
+ # Double empty lines are useful to separate conceptually different methods
51
+ # in the same class or module.
52
+ Style/EmptyLines:
53
+ Enabled: false
54
+
55
+ # In most cases, a space is nice. Sometimes, it's not.
56
+ # Just be consistent with the rest of the surrounding code.
57
+ Style/EmptyLinesAroundClassBody:
58
+ Enabled: false
59
+
60
+ # In most cases, a space is nice. Sometimes, it's not.
61
+ # Just be consistent with the rest of the surrounding code.
62
+ Style/EmptyLinesAroundModuleBody:
63
+ Enabled: false
64
+
65
+ # I personally don't care about the format style.
66
+ # In most cases I like to use %, but not at the point I want to enforce it
67
+ # as a convention in the entire code.
68
+ Style/FormatString:
69
+ Enabled: false
70
+
71
+ # Prefer the latest Hash syntax
72
+ Style/HashSyntax:
73
+ Exclude:
74
+ # But Rakefiles generally have some definition like
75
+ # :default => :test
76
+ # that looks nicer with the old rocket syntax.
77
+ - 'Rakefile'
78
+
79
+ # Array indentation should be considered like MultilineMethodCallIndentation indentation
80
+ # and use 4 spaces instead of 2.
81
+ Style/IndentArray:
82
+ IndentationWidth: 4
83
+
84
+ # Hash indentation should be considered like MultilineMethodCallIndentation indentation
85
+ # and use 4 spaces instead of 2.
86
+ Style/IndentHash:
87
+ IndentationWidth: 4
88
+
89
+ # Multi-line differs from standard indentation, they are indented twice.
90
+ Style/MultilineMethodCallIndentation:
91
+ EnforcedStyle: indented
92
+ IndentationWidth: 4
93
+
94
+ Style/IfUnlessModifier:
95
+ Enabled: false
96
+
97
+ # unless is not always cool.
98
+ Style/NegatedIf:
99
+ Enabled: false
100
+
101
+ # There are cases were the inline rescue is ok. We can either downgrade the severity,
102
+ # or rely on the developer judgement on a case-by-case basis.
103
+ Style/RescueModifier:
104
+ Enabled: false
105
+
106
+ # Hate It or Love It, I prefer double quotes as this is more consistent
107
+ # with several other programming languages and the output of puts and inspect.
108
+ Style/StringLiterals:
109
+ EnforcedStyle: double_quotes
110
+
111
+ # It's nice to be consistent. The trailing comma also allows easy reordering,
112
+ # and doesn't cause a diff in Git when you add a line to the bottom.
113
+ Style/TrailingCommaInLiteral:
114
+ EnforcedStyleForMultiline: consistent_comma
115
+
116
+ Style/TrivialAccessors:
117
+ # IgnoreClassMethods because I want to be able to define class-level accessors
118
+ # that sets an instance variable on the metaclass, such as:
119
+ #
120
+ # def self.default=(value)
121
+ # @default = value
122
+ # end
123
+ #
124
+ IgnoreClassMethods: true
125
+
126
+ Style/WordArray:
127
+ Enabled: false
@@ -3,9 +3,16 @@ rvm:
3
3
  - 2.0
4
4
  - 2.1
5
5
  - 2.2
6
+ - 2.3.0
7
+ - jruby-9.0.5.0
6
8
  - ruby-head
7
- - jruby-19mode
8
- - rbx-19mode
9
+
10
+ sudo: false
11
+ cache:
12
+ - bundler
13
+
14
+ env:
15
+ - COVERALL=1
9
16
 
10
17
  notifications:
11
18
  recipients:
@@ -13,7 +20,5 @@ notifications:
13
20
 
14
21
  matrix:
15
22
  allow_failures:
16
- - rvm: rbx-19mode
17
- - rvm: jruby-19mode
18
23
  - rvm: ruby-head
19
-
24
+ - rvm: jruby-9.0.5.0
@@ -0,0 +1,35 @@
1
+ # Welcome to PublicSuffix 2.0!
2
+
3
+ PublicSuffix 2.0 contains a rewritten internal representation and comparison logic, that drastically increases the lookup performance. The new version also changes several internal and external API.
4
+
5
+ This document documents the most relevant changes to help you upgrading from PublicSuffix 1.0 to 2.0.
6
+
7
+ ## What's New
8
+
9
+ - The library is now 100% compliants with the official PublicSuffix tests. The major breaking change you may experience, is that if a domain passed as input doesn't match any rule, the rule `*` is assumed. You can override this behavior by passing a custom default rule with the `default_rule` option.
10
+ - `PublicSuffix.domain` is a new method that parses the input and returns the domain (combination of second level domain + suffix). This is a convenient helper to parse a domain name, for example when you need to determine the cookie or SSL scope.
11
+ - Added the ability to disable the use of private domains either at runtime, in addition to the ability to not load the private domains section when reading the list (`private_domains: false`). This feature also superseded the `private_domains` class-level attribute, that is no longer available.
12
+
13
+ ## Upgrade
14
+
15
+ When upgrading, here's the most relevant changes to keep an eye on:
16
+
17
+ - Several futile utility helpers were removed, such as `Domain#rule`, `Domain#is_a_domain?`, `Domain#is_a_subdomain?`, `Domain#valid?`. You can easily obtain the same result by having a custom method that reconstructs the logic, and/or calling `PublicSuffix.{domain|parse}(domain.to_s)`.
18
+ - `PublicSuffix::List.private_domains` is no longer available. Instead, you now have two ways to enable/disable the private domains:
19
+
20
+ 1. At runtime, by using the `ignore_private` option
21
+
22
+ ```ruby
23
+ PublicSuffix.domain("something.blogspot.com", ignore_private: true)
24
+ ```
25
+
26
+ 1. Loading a filtered list:
27
+
28
+ ```ruby
29
+ # Disable support for private TLDs
30
+ PublicSuffix::List.default = Public::Suffix.parse(File.read(Public::Suffix::DEFAULT_LIST_PATH), private_domains: false)
31
+ # => "blogspot.com"
32
+ PublicSuffix.domain("something.blogspot.com")
33
+ # => "blogspot.com"
34
+ ```
35
+
@@ -1,6 +1,31 @@
1
1
  # Changelog
2
2
 
3
3
 
4
+ #### Release 2.0.0
5
+
6
+ - NEW: Added PublicSuffix.domain # => sld.tld
7
+
8
+ - NEW: Added the ability to disable the use of private domains either at runtime, in addition to the ability to not load the private domains section when reading the list (`private_domains: false`). This feature also superseded the `private_domains` class-level attribute, that is no longer available.
9
+
10
+ - CHANGED: Considerable performance improvements (GH-92)
11
+
12
+ - CHANGED: Updated definitions.
13
+
14
+ - CHANGED: Removed deprecated PublicSuffix::InvalidDomain exception
15
+
16
+ - CHANGED: If the suffix is now listed, then the prevaling rule is "*" as defined by the PSL algorithm (GH-91)
17
+
18
+ - CHANGED: Input validation is performed only if you call `PublicSuffix.parse` or `PublicSuffix.list`
19
+
20
+ - CHANGED: Input with leading dot is invalid per PSL acceptance tests
21
+
22
+ - CHANGED: Removed `private_domains` class-level attribute. It is replaced by the `private_domains: false` option in the list parse method.
23
+
24
+ - CHANGED: The default list now assumes you use UTF-8 for reading the input (GH-94),
25
+
26
+ - REMOVED: Removed futile utility helpers such as `Domain#rule`, `Domain#is_a_domain?`, `Domain#is_a_subdomain?`, `Domain#valid?`. You can easily obtain the same result by having a custom method that reconstructs the logic, and/or calling `PublicSuffix.{domain|parse}(domain.to_s)`.
27
+
28
+
4
29
  #### Release 1.5.3
5
30
 
6
31
  - FIXED: Don't duplicate rule indices when creating index (GH-77). [Thanks @ags]
data/Gemfile CHANGED
@@ -2,4 +2,10 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'minitest'
5
+ gem "rake", "< 11"
6
+ gem "minitest"
7
+ gem "minitest-reporters"
8
+ gem "coveralls", require: false
9
+ gem "rubocop", require: false
10
+
11
+ gem "memory_profiler", require: false if !RUBY_VERSION.start_with?("2.0")
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2015 Simone Carletti <weppos@weppos.net>
1
+ Copyright (c) 2009-2016 Simone Carletti <weppos@weppos.net>
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,55 +1,47 @@
1
- # Public Suffix List
1
+ # Public Suffix <small>Ruby</small>
2
2
 
3
- <tt>PublicSuffix</tt> is a Ruby domain name parser based on the [Public Suffix List](http://publicsuffix.org/).
3
+ <tt>PublicSuffix</tt> is a Ruby domain name parser based on the [Public Suffix List](https://publicsuffix.org/).
4
4
 
5
- [![Build Status](https://secure.travis-ci.org/weppos/publicsuffix-ruby.png)](http://travis-ci.org/weppos/publicsuffix-ruby)
6
-
7
-
8
- ## What is the Public Suffix List?
9
-
10
- The Public Suffix List is a cross-vendor initiative to provide an accurate list of domain name suffixes.
11
-
12
- The Public Suffix List is an initiative of the Mozilla Project, but is maintained as a community resource. It is available for use in any software, but was originally created to meet the needs of browser manufacturers.
13
-
14
- A "public suffix" is one under which Internet users can directly register names. Some examples of public suffixes are ".com", ".co.uk" and "pvt.k12.wy.us". The Public Suffix List is a list of all known public suffixes.
15
-
16
- Source: http://publicsuffix.org
17
-
18
-
19
- ## Why the Public Suffix List is better than any available Regular Expression parser?
20
-
21
- Previously, browsers used an algorithm which basically only denied setting wide-ranging cookies for top-level domains with no dots (e.g. com or org). However, this did not work for top-level domains where only third-level registrations are allowed (e.g. co.uk). In these cases, websites could set a cookie for co.uk which will be passed onto every website registered under co.uk.
22
-
23
- Clearly, this was a security risk as it allowed websites other than the one setting the cookie to read it, and therefore potentially extract sensitive information.
24
-
25
- Since there is no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain (the policies differ with each registry), the only method is to create a list of all top-level domains and the level at which domains can be registered. This is the aim of the effective TLD list.
26
-
27
- As well as being used to prevent cookies from being set where they shouldn't be, the list can also potentially be used for other applications where the registry controlled and privately controlled parts of a domain name need to be known, for example when grouping by top-level domains.
28
-
29
- Source: https://wiki.mozilla.org/Public_Suffix_List
30
-
31
- Not convinced yet? Check out [this real world example](http://stackoverflow.com/q/288810/123527).
5
+ [![Build Status](https://travis-ci.org/weppos/publicsuffix-ruby.svg?branch=master)](https://travis-ci.org/weppos/publicsuffix-ruby)
32
6
 
33
7
 
34
8
  ## Requirements
35
9
 
36
10
  - Ruby >= 2.0
37
11
 
38
- For an older versions of Ruby use a previous release. We also support several [Ruby implementations](http://simonecarletti.com/code/publicsuffix/#implementations).
12
+ For an older versions of Ruby use a previous release.
39
13
 
40
14
 
41
15
  ## Installation
42
16
 
43
- The best way to install *PublicSuffix* is via [RubyGems](https://rubygems.org/).
17
+ You can install the gem manually:
18
+
19
+ ```shell
20
+ $ gem install public_suffix
21
+ ```
44
22
 
45
- $ gem install public_suffix
23
+ Or use Bundler and define it as a dependency in your `Gemfile`:
46
24
 
47
- You might need administrator privileges on your system to install the gem.
25
+ ```shell
26
+ $ gem 'public_suffix'
27
+ ```
48
28
 
29
+ If you are upgrading to 2.0, see [2.0-Upgrade.md](2.0-Upgrade.md).
49
30
 
50
- ## Basic Usage
31
+ ## Usage
51
32
 
52
- Example domain without subdomains.
33
+ Extract the domain out from a name:
34
+
35
+ ```ruby
36
+ PublicSuffix.domain("google.com")
37
+ # => "google.com"
38
+ PublicSuffix.domain("www.google.com")
39
+ # => "google.com"
40
+ PublicSuffix.domain("www.google.co.uk")
41
+ # => "google.co.uk"
42
+ ```
43
+
44
+ Parse a domain without subdomains:
53
45
 
54
46
  ```ruby
55
47
  domain = PublicSuffix.parse("google.com")
@@ -66,7 +58,7 @@ domain.subdomain
66
58
  # => nil
67
59
  ```
68
60
 
69
- Example domain with subdomains.
61
+ Parse a domain with subdomains:
70
62
 
71
63
  ```ruby
72
64
  domain = PublicSuffix.parse("www.google.com")
@@ -83,7 +75,7 @@ domain.subdomain
83
75
  # => "www.google.com"
84
76
  ```
85
77
 
86
- Simple validation example.
78
+ Simple validation example:
87
79
 
88
80
  ```ruby
89
81
  PublicSuffix.valid?("google.com")
@@ -92,7 +84,8 @@ PublicSuffix.valid?("google.com")
92
84
  PublicSuffix.valid?("www.google.com")
93
85
  # => true
94
86
 
95
- PublicSuffix.valid?("x.yz")
87
+ # Explicitly forbidden, it is listed as a private domain
88
+ PublicSuffix.valid?("blogspot.com")
96
89
  # => false
97
90
  ```
98
91
 
@@ -102,38 +95,72 @@ This library automatically recognizes Fully Qualified Domain Names. A FQDN is a
102
95
 
103
96
  ```ruby
104
97
  # Parse a standard domain name
105
- domain = PublicSuffix.parse("www.google.com")
106
- # => #<PublicSuffix::Domain>
107
- domain.tld
108
- # => "com"
98
+ PublicSuffix.domain("www.google.com")
99
+ # => "domain.com"
109
100
 
110
101
  # Parse a fully qualified domain name
111
- domain = PublicSuffix.parse("www.google.com.")
112
- # => #<PublicSuffix::Domain>
113
- domain.tld
114
- # => "com"
102
+ PublicSuffix.domain("www.google.com.")
103
+ # => "domain.com"
115
104
  ```
116
105
 
117
106
  ## Private domains
118
107
 
119
- This library has support for switching off support for private (non-ICANN) domains
108
+ This library has support for switching off support for private (non-ICANN).
120
109
 
121
110
  ```ruby
122
- # Parse a domain on a private TLD
123
- domain = PublicSuffix.parse("something.blogspot.com")
124
- # => #<PublicSuffix::Domain>
125
- domain.tld
111
+ # Extract a domain including private domains (by default)
112
+ PublicSuffix.domain("something.blogspot.com")
113
+ # => "something.blogspot.com"
114
+
115
+ # Extract a domain excluding private domains
116
+ PublicSuffix.domain("something.blogspot.com", ignore_private: true)
126
117
  # => "blogspot.com"
127
118
 
119
+ # It also works for #parse and #valid?
120
+ PublicSuffix.parse("something.blogspot.com", ignore_private: true)
121
+ PublicSuffix.valid?("something.blogspot.com", ignore_private: true)
122
+ ```
123
+
124
+ If you don't care about private domains at all, it's more efficient to exclude them when the list is parsed:
125
+
126
+ ```ruby
128
127
  # Disable support for private TLDs
129
- PublicSuffix::List.private_domains = false
130
- # => #<PublicSuffix::List>
131
- domain = PublicSuffix.parse("something.blogspot.com")
132
- # => #<PublicSuffix::Domain>
133
- domain.tld
134
- # => "com"
128
+ PublicSuffix::List.default = Public::Suffix.parse(File.read(Public::Suffix::DEFAULT_LIST_PATH), private_domains: false)
129
+ # => "blogspot.com"
130
+ PublicSuffix.domain("something.blogspot.com")
131
+ # => "blogspot.com"
135
132
  ```
136
133
 
134
+
135
+ ## What is the Public Suffix List?
136
+
137
+ The [Public Suffix List](https://publicsuffix.org) is a cross-vendor initiative to provide an accurate list of domain name suffixes.
138
+
139
+ The Public Suffix List is an initiative of the Mozilla Project, but is maintained as a community resource. It is available for use in any software, but was originally created to meet the needs of browser manufacturers.
140
+
141
+ A "public suffix" is one under which Internet users can directly register names. Some examples of public suffixes are ".com", ".co.uk" and "pvt.k12.wy.us". The Public Suffix List is a list of all known public suffixes.
142
+
143
+
144
+ ## Why the Public Suffix List is better than any available Regular Expression parser?
145
+
146
+ Previously, browsers used an algorithm which basically only denied setting wide-ranging cookies for top-level domains with no dots (e.g. com or org). However, this did not work for top-level domains where only third-level registrations are allowed (e.g. co.uk). In these cases, websites could set a cookie for co.uk which will be passed onto every website registered under co.uk.
147
+
148
+ Clearly, this was a security risk as it allowed websites other than the one setting the cookie to read it, and therefore potentially extract sensitive information.
149
+
150
+ Since there is no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain (the policies differ with each registry), the only method is to create a list of all top-level domains and the level at which domains can be registered. This is the aim of the effective TLD list.
151
+
152
+ As well as being used to prevent cookies from being set where they shouldn't be, the list can also potentially be used for other applications where the registry controlled and privately controlled parts of a domain name need to be known, for example when grouping by top-level domains.
153
+
154
+ Source: https://wiki.mozilla.org/Public_Suffix_List
155
+
156
+ Not convinced yet? Check out [this real world example](https://stackoverflow.com/q/288810/123527).
157
+
158
+
159
+ ## Does <tt>PublicSuffix</tt> make requests to Public Suffix List website?
160
+
161
+ No. <tt>PublicSuffix</tt> comes with a bundled list. It does not make any HTTP requests to parse or validate a domain.
162
+
163
+
137
164
  ## Feedback and bug reports
138
165
 
139
166
  If you use this library and find yourself missing any functionality, please [let me know](mailto:weppos@weppos.net).
@@ -145,10 +172,10 @@ Report issues or feature requests to [GitHub Issues](https://github.com/weppos/p
145
172
 
146
173
  ## More
147
174
 
148
- * [Homepage](http://simonecarletti.com/code/publicsuffix)
149
- * [Repository](https://github.com/weppos/publicsuffix-ruby)
150
- * [API Documentation](http://rubydoc.info/gems/public_suffix)
151
- * [Introducing the Public Suffix List library for Ruby](http://simonecarletti.com/blog/2010/06/public-suffix-list-library-for-ruby/)
175
+ - [Homepage](https://simonecarletti.com/code/publicsuffix-ruby)
176
+ - [Repository](https://github.com/weppos/publicsuffix-ruby)
177
+ - [API Documentation](http://rubydoc.info/gems/public_suffix)
178
+ - [Introducing the Public Suffix List library for Ruby](https://simonecarletti.com/blog/2010/06/public-suffix-list-library-for-ruby/)
152
179
 
153
180
 
154
181
  ## Changelog
@@ -158,4 +185,4 @@ See the [CHANGELOG.md](CHANGELOG.md) file for details.
158
185
 
159
186
  ## License
160
187
 
161
- Copyright (c) 2009-2015 Simone Carletti. This is Free Software distributed under the MIT license.
188
+ Copyright (c) 2009-2016 Simone Carletti. This is Free Software distributed under the MIT license.