Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSL auto-update #3

Open
wants to merge 471 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
471 commits
Select commit Hold shift + click to select a range
1c4f0ca
Optimize space by removing duplicate rule value
weppos Jan 24, 2017
ac39e08
Allocation comparison with master is way lowe
weppos Jan 24, 2017
24ad179
Restructure Rule initialization
weppos Jan 24, 2017
d363dbe
Introduce Entry internal object
weppos Jan 24, 2017
b7fec8b
Simplify reference to list path
weppos Jan 28, 2017
582efe5
Change bm_find.rb benchmark to not run on private rules
weppos Feb 9, 2017
740d78c
Work around some limitations of ObjectSpace.memsize_of
weppos Feb 9, 2017
c3e05d5
Fix outdated namespace
weppos Feb 9, 2017
4d98521
Measure the list size
weppos Feb 9, 2017
fff9739
Cleanup docs
weppos Feb 9, 2017
498e19b
Merge branch 'master' into thesis-hash
weppos Feb 9, 2017
482f534
The Hash implementation has no longer indexes
weppos Feb 9, 2017
8f241cc
Add # of rules in the benchmark info
weppos Feb 9, 2017
dd82821
Make ObjectBinsize run the demo by default
weppos Feb 9, 2017
2a79a0f
Merge branch 'master' into thesis-hash
weppos Feb 9, 2017
c6560dc
Dropped support for Ruby < 2.1
weppos Feb 9, 2017
f1abbd3
Remove unnecessary string allocations
weppos Feb 9, 2017
c45dc94
Merge pull request #133 from weppos/thesis-hash
weppos Feb 10, 2017
7b600f3
[DOCS] corrects param name in List#parse
typeoneerror Mar 25, 2017
eae246a
Merge pull request #135 from typeoneerror/hotfix-docs-typo
weppos Mar 25, 2017
52b2343
Update list
weppos Apr 10, 2017
578737c
Rubocop 0.48.1 is buggy
weppos Apr 10, 2017
bb12e71
Improve and correct documentation
pjg Jun 9, 2017
66698da
Create README.md
weppos Jun 10, 2017
86721b2
Merge pull request #140 from pjg/improve-documentation-and-code-comments
weppos Jun 10, 2017
16a502f
Add PSL license info to the README (closes GH-137)
weppos Jun 28, 2017
6f175d6
Fix rubocop new preferences
weppos Aug 4, 2017
97ef80b
Update definitions
weppos Aug 4, 2017
995e9e5
Updated CHANGELOG information about GH-133
weppos Aug 4, 2017
3a8a8c5
Release 3.0.0
weppos Aug 4, 2017
a157c3d
Update Travis config
weppos Aug 4, 2017
dc7702d
2.0 is no longer supported
weppos Aug 4, 2017
03436a8
Fix wrong docs
weppos Oct 31, 2017
f1b3142
Fix Rubocop offenses
weppos Oct 31, 2017
ad6a326
Improve performance and avoid allocation.
Nov 8, 2017
1c6742f
Merge pull request #146 from clearbit/master
weppos Nov 8, 2017
8a2baf1
Updated definitions
weppos Nov 8, 2017
d63f20c
Changelog for GH-146
weppos Nov 8, 2017
0c0561d
Release 3.0.1
weppos Nov 8, 2017
844f898
Update Rubocop
weppos Feb 12, 2018
15d1739
Test against 2.5 (closes GH-148)
weppos Feb 12, 2018
da7b20b
Update definitions
weppos Feb 12, 2018
65ab7c9
Release 3.0.2
weppos Feb 12, 2018
8bbd236
Update docblock
weppos Jun 11, 2018
8841e49
Update .rubocop_defaults.yml (#153)
jonhue Jun 26, 2018
4556aa4
Fix Rubocop new warnings
weppos Jun 26, 2018
a9feb70
Update definitions (#154)
wcmonty Aug 15, 2018
93aad6a
Release 3.0.3
weppos Aug 15, 2018
65e7b5f
Update .travis.yml
weppos Oct 29, 2018
38b89a9
Switch to CodeCov
weppos Oct 29, 2018
f749c1a
Fix offenses
weppos Oct 29, 2018
916d013
Fix typo in comment (#159)
pcai Apr 25, 2019
f05f156
Make Travis happy
weppos Apr 25, 2019
1fb5578
Upgrade Bundler
weppos Apr 25, 2019
1f10154
Minimum Ruby version is 2.3
weppos Apr 25, 2019
2803479
Fix version mismatch
weppos Apr 25, 2019
d3ea96c
Upgrade to Rubocop 0.70
weppos May 27, 2019
245836e
Update definitions list (#160)
GQuirino May 27, 2019
22ce7d5
Release 3.1.0
weppos May 27, 2019
732a651
Fix version in README
weppos May 27, 2019
34046e3
Update PSL
weppos Jun 25, 2019
ae7cf82
Reinstate support to Ruby 2.1 and 2.2
weppos Jun 25, 2019
ed7c414
Release 3.1.1
weppos Jun 25, 2019
d6e4914
Remove support for Ruby < 2.3 in major version
weppos Jun 25, 2019
87343b8
Release 4.0.0
weppos Jun 25, 2019
27d9ff9
Test Ruby 2.7
weppos Jun 25, 2019
3648a1c
Create FUNDING.yml
weppos Jun 26, 2019
da7f5a8
Add Tidelift link
weppos Aug 9, 2019
76bb080
Updated definitions
weppos Aug 9, 2019
1a17386
Release 4.0.1
weppos Aug 9, 2019
e03a267
Update CHANGELOG.md
weppos Aug 23, 2019
894cceb
Create SECURITY.md
weppos Aug 23, 2019
3d6b74c
Update README.md
weppos Aug 23, 2019
626883d
Release 4.0.2
weppos Dec 27, 2019
af3244f
Update rubocop
weppos Dec 27, 2019
ec6bc1d
Experiment with https://keepachangelog.com/
weppos Dec 27, 2019
d076009
Update .travis.yml
weppos Jan 5, 2020
bac3a1d
Fix 2.7 deprecations and warnings (#168)
BrianHawley Jan 5, 2020
41f54ea
CHANGELOG for GH-167
weppos Jan 5, 2020
da650c8
Welcome 2020
weppos Jan 5, 2020
84fc0d1
Release 4.0.3
weppos Jan 5, 2020
c65e0e4
Move development dependencies from gemspec to Bundle
weppos Jan 31, 2020
c14c3ed
Sync up my Rubocop default file
weppos Jan 31, 2020
9947cca
Update definitions
weppos Jan 31, 2020
369b177
Update .gitignore
weppos Jan 31, 2020
b8f8145
Update README.md
weppos Feb 15, 2020
929532d
Update README.md
weppos Feb 15, 2020
16695da
Update SECURITY.md
weppos Feb 16, 2020
ee03cb4
Update rubocop requirement from 0.79.0 to 0.80.0 (#169)
dependabot-preview[bot] Feb 19, 2020
c6dcdf6
Update rubocop requirement from 0.80.0 to 0.80.1 (#170)
dependabot-preview[bot] Mar 3, 2020
da6e504
Update to Rubocop 0.81.0
weppos Apr 5, 2020
167552c
Update definitions
weppos Apr 5, 2020
a98db48
Release 4.0.3
weppos Apr 5, 2020
8d034e3
Update Travis badge link
weppos Apr 5, 2020
6f650da
Create codecov.yml
weppos Apr 7, 2020
6465387
Update definitions
weppos May 9, 2020
db463e5
Add project metadata to the gemspec (#172)
orien May 9, 2020
8eb07f7
Add CI workflow
weppos May 9, 2020
8ce9f8c
Update tests.yml
weppos May 9, 2020
4fc6126
Update tests.yml
weppos May 9, 2020
f0cc99e
Release 4.0.5
weppos May 9, 2020
c101bd5
Fix key duplication in codecov.yml (#175)
dduugg Aug 4, 2020
89c74b0
Updated definitions
weppos Sep 2, 2020
c61d25e
Update rubocop
weppos Sep 2, 2020
e3eedfd
Ignore rubocop cop
weppos Sep 2, 2020
a302119
Last release with 2.3
weppos Sep 2, 2020
2e0bee3
Release 4.0.6
weppos Sep 2, 2020
0898e5a
Add definitions section to README.md (#176)
cseeman Sep 2, 2020
ba72b15
Disable Lint/ConstantDefinitionInBlock in specs
weppos Sep 30, 2020
6fa9751
Disable Lint/ConstantDefinitionInBlock in Rakefile
weppos Sep 30, 2020
d6c251a
Create Dependabot config file (#178)
dependabot-preview[bot] Jan 6, 2021
c4c3012
Use instance_of? instead of comparing classes
Jan 6, 2021
db76aea
Disable Coverage
weppos Apr 30, 2021
f03cec8
Test with Ruby 3
weppos Apr 30, 2021
c50a052
CI: Remove EOL versions
Dec 3, 2021
47bee57
Format
Dec 3, 2021
450825e
Replace Travis with GitHub Actions
Dec 3, 2021
da31476
Delete .travis.yml
Dec 3, 2021
405c291
Add Ruby 3.1 to CI (#185)
petergoldstein Jan 10, 2022
434f0bd
Add release workflow
weppos Apr 12, 2022
b741b4f
Fixed YARD rake task
weppos Apr 12, 2022
f153a19
Update data list (#186)
wmontgomery-splunk Apr 12, 2022
0028a2f
Update definitions
weppos Apr 12, 2022
cfd3381
Update year
weppos Apr 12, 2022
071ba49
Release 4.0.7
weppos Apr 12, 2022
f5e7254
CI: use bundler-cache (#187)
olleolleolle Apr 12, 2022
2396b08
Update tests.yml
weppos Jul 14, 2022
fb74b44
Update tests.yml
weppos Jul 14, 2022
7e2008e
Setup autoupdate workflow
weppos Jul 24, 2022
a4a0f5a
Update release.yml
weppos Jul 24, 2022
ff46557
Update psl-update.yml
weppos Jul 24, 2022
b2e3932
Update psl-update.yml
weppos Jul 24, 2022
013e6d1
psl-update: Ensure pull request exclude vendor
weppos Jul 24, 2022
bf4d0f8
psl-update: Avoid changes being committed
weppos Jul 24, 2022
15d8497
psl-update: Avoid vendor changes being committed
weppos Jul 24, 2022
aa8ab9a
Updated list from source (#193)
github-actions[bot] Jul 24, 2022
5e3379b
Update rubocop
weppos Jul 24, 2022
0a0ad7d
Update workflowa
weppos Jul 24, 2022
4017771
Update tests.yml
weppos Jul 24, 2022
da5bbc7
Revert "Update rubocop"
weppos Jul 24, 2022
3696c1c
Restore Rubocop
weppos Jul 24, 2022
c36b40c
Upgrade Rubocop
weppos Jul 24, 2022
585e678
Upgrade Rubocop to 1.x
weppos Jul 24, 2022
3e32063
Release 5.0.0
weppos Jul 24, 2022
a9612d1
Updated list from source (#194)
github-actions[bot] Jul 29, 2022
94262be
Updated list from source (#195)
github-actions[bot] Aug 6, 2022
2d0c186
Updated list from source (#196)
github-actions[bot] Aug 16, 2022
d4077ae
Update dependabot.yml
weppos Aug 22, 2022
c62a0c8
Updated list from source (#198)
github-actions[bot] Sep 2, 2022
f86639f
Updated list from source (#199)
github-actions[bot] Sep 4, 2022
c101e0b
Updated list from source (#200)
github-actions[bot] Sep 16, 2022
4ebb6ea
Updated list from source (#201)
github-actions[bot] Sep 23, 2022
c495417
Updated list from source (#202)
github-actions[bot] Sep 28, 2022
c870183
Updated list from source (#203)
github-actions[bot] Oct 4, 2022
02b372a
Updated list from source (#204)
github-actions[bot] Oct 8, 2022
dae6552
Updated list from source (#205)
github-actions[bot] Oct 12, 2022
a3c6422
Updated list from source (#206)
github-actions[bot] Oct 13, 2022
3dc11d8
Updated list from source (#207)
github-actions[bot] Oct 14, 2022
2f606fd
Updated list from source (#208)
github-actions[bot] Oct 16, 2022
7fc5e5f
Updated list from source (#209)
github-actions[bot] Oct 21, 2022
aac50a4
Updated list from source (#210)
github-actions[bot] Oct 31, 2022
b88102c
Updated list from source (#211)
github-actions[bot] Nov 3, 2022
d002043
Lock mocha dependency
weppos Nov 3, 2022
dce8d77
Update mocha requirement from ~> 1.16.0 to ~> 2.0.1 (#212)
dependabot[bot] Nov 4, 2022
3e89be0
Updated list from source (#213)
github-actions[bot] Nov 5, 2022
b847179
Updated list from source (#214)
github-actions[bot] Nov 11, 2022
126f555
Bump cadwallion/publish-rubygems-action (#215)
dependabot[bot] Nov 15, 2022
5b8a29e
Updated list from source (#216)
github-actions[bot] Nov 16, 2022
0432e07
Updated list from source (#217)
github-actions[bot] Nov 23, 2022
e237cf5
Updated list from source (#219)
github-actions[bot] Nov 24, 2022
f4daa1a
Updated list from source (#220)
github-actions[bot] Nov 30, 2022
8985740
Release 5.0.1
weppos Dec 7, 2022
3fe4612
Updated list from source (#222)
github-actions[bot] Dec 9, 2022
bc53ab7
Add Ruby 3.2 to the CI matrix (#223)
petergoldstein Jan 26, 2023
668bda5
Updated list from source (#224)
github-actions[bot] Jan 31, 2023
3f811b3
Updated list from source (#225)
github-actions[bot] Feb 1, 2023
69a78ae
Updated list from source (#226)
github-actions[bot] Feb 9, 2023
d9d921e
Updated list from source (#227)
github-actions[bot] Feb 11, 2023
f0f0ac6
Updated list from source (#228)
github-actions[bot] Feb 20, 2023
bb3cbc4
Updated list from source (#229)
github-actions[bot] Feb 23, 2023
f332e64
Updated list from source (#231)
github-actions[bot] Feb 27, 2023
33daaef
Updated list from source (#232)
github-actions[bot] Feb 28, 2023
5af597a
Updated list from source (#233)
github-actions[bot] Mar 9, 2023
207e29b
Updated list from source (#235)
github-actions[bot] Mar 20, 2023
c3671ed
Updated list from source (#236)
github-actions[bot] Apr 12, 2023
5919f4b
Updated list from source (#238)
github-actions[bot] Apr 16, 2023
f8d9f8f
Updated list from source (#239)
github-actions[bot] Apr 27, 2023
907df69
Bump peter-evans/create-pull-request from 4 to 5 (#237)
dependabot[bot] Apr 28, 2023
cdb1cd2
Updated list from source (#240)
github-actions[bot] May 5, 2023
37dac97
README: Document how to add a custom domain to the list (#221)
andreynering May 12, 2023
3d5b07e
Updated list from source (#241)
github-actions[bot] Jun 8, 2023
baa3784
Updated list from source (#242)
github-actions[bot] Jun 12, 2023
1dc447d
Updated list from source (#243)
github-actions[bot] Jun 14, 2023
76e85e0
Updated list from source (#244)
github-actions[bot] Jun 15, 2023
3cc407c
Updated list from source (#245)
github-actions[bot] Jun 20, 2023
58a964e
Updated list from source (#247)
github-actions[bot] Jul 1, 2023
d673b2a
Updated list from source (#248)
github-actions[bot] Jul 3, 2023
2b46c08
Updated list from source (#249)
github-actions[bot] Jul 10, 2023
fe724c2
Update year
weppos Jul 11, 2023
d5739ad
Release 5.0.2
weppos Jul 11, 2023
0b06867
Fix Ruby release workflow
weppos Jul 11, 2023
1ac1ae4
Release 5.0.3
weppos Jul 11, 2023
6e1d94c
Update FUNDING.yml
weppos Jul 12, 2023
57e4d81
Updated list from source (#250)
github-actions[bot] Jul 18, 2023
00a8ec3
Fix spacing
weppos Jul 18, 2023
462b680
Update mocha requirement from ~> 2.0.1 to ~> 2.1.0 (#251)
dependabot[bot] Jul 28, 2023
66e252d
Updated list from source (#252)
github-actions[bot] Jul 30, 2023
650faae
Updated list from source (#253)
github-actions[bot] Aug 4, 2023
48d4759
Updated list from source (#254)
github-actions[bot] Aug 6, 2023
9e50afb
Updated list from source (#255)
github-actions[bot] Aug 11, 2023
251ae70
Updated list from source (#256)
github-actions[bot] Aug 25, 2023
3500941
Updated list from source (#257)
github-actions[bot] Aug 27, 2023
4883fbd
Reduce gem size (#258)
ybiquitous Aug 31, 2023
b0bde49
Update SECURITY.md
weppos Aug 31, 2023
e05b7a2
Update SECURITY.md
weppos Aug 31, 2023
2a84a64
Reorganize public_suffix.gemspec
weppos Aug 31, 2023
26e0fee
CHANGELOG for GH-259
weppos Aug 31, 2023
0616990
Bump actions/checkout from 3 to 4 (#260)
dependabot[bot] Sep 5, 2023
7729825
Updated list from source (#261)
github-actions[bot] Sep 18, 2023
892f94d
Updated list from source (#262)
github-actions[bot] Sep 20, 2023
8eda272
Updated list from source (#263)
github-actions[bot] Sep 26, 2023
df92b8c
Updated list from source (#264)
github-actions[bot] Oct 2, 2023
07ddcab
Updated list from source (#266)
github-actions[bot] Oct 19, 2023
df38193
Updated list from source (#267)
github-actions[bot] Nov 4, 2023
d8b853a
Updated list from source (#269)
github-actions[bot] Nov 9, 2023
a311826
Release 5.0.4
weppos Nov 17, 2023
a86b1e5
Update release.yml
weppos Nov 17, 2023
d500f07
Update release.yml
weppos Nov 17, 2023
30639a3
Updated list from source (#270)
github-actions[bot] Nov 20, 2023
b57b9e0
chore(changelog): fix wrong linked pull request (#271)
andreynering Nov 20, 2023
1a707b3
Updated list from source (#272)
github-actions[bot] Nov 21, 2023
0bdaf0f
Updated list from source (#273)
github-actions[bot] Nov 22, 2023
3a60e5e
Updated list from source (#274)
github-actions[bot] Dec 7, 2023
26d0eb9
Updated list from source (#275)
github-actions[bot] Dec 14, 2023
74189a3
Updated list from source (#276)
github-actions[bot] Jan 8, 2024
d7bd1be
Updated list from source (#277)
github-actions[bot] Jan 24, 2024
65c71b2
Updated list from source (#278)
github-actions[bot] Jan 25, 2024
629f05c
Updated list from source (#279)
github-actions[bot] Jan 29, 2024
94662e0
Updated list from source (#280)
github-actions[bot] Jan 31, 2024
ada7d78
Add Ruby 3.3 to CI matrix (#281)
m-nakamura145 Jan 31, 2024
30b3c88
Bump peter-evans/create-pull-request from 5 to 6 (#282)
dependabot[bot] Feb 1, 2024
6a3e271
Updated list from source (#283)
github-actions[bot] Feb 2, 2024
149a844
Updated list from source (#284)
github-actions[bot] Feb 5, 2024
4fc38de
Updated list from source (#285)
github-actions[bot] Feb 6, 2024
a245df3
Updated list from source (#286)
github-actions[bot] Feb 9, 2024
42cad0a
Updated list from source (#287)
github-actions[bot] Feb 19, 2024
f8555d3
Updated list from source (#288)
github-actions[bot] Mar 3, 2024
a82ae30
Updated list from source (#289)
github-actions[bot] Mar 27, 2024
185a93d
Merge branch 'moz' into master
abhishekk1903 Apr 2, 2024
b357766
Updated list from source
abhishekk1903 Apr 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: ruby

rvm:
- 2.0
- 2.1
- 2.2
- 2.3.3
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### master

- CHANGED: Dropped support for Ruby < 2.1
- CHANGED: `PublicSuffix::List#rules` is now protected. You should not rely on it as the internal rule representation is subject to change to optimize performances.
- CHANGED: Removed `PublicSuffix::List.clear`, it was an unnecessary accessor method. Use `PublicSuffix::List.default = nil` if you **really** need to reset the default list. You shouldn't.
- CHANGED: `PublicSuffix::List#select` is now private. You should not use it, instead use ``PublicSuffix::List#find`.
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ gem "minitest"
gem "minitest-reporters"
gem "rubocop", require: false

gem "memory_profiler", require: false if !RUBY_VERSION.start_with?("2.0")
gem "memory_profiler", require: false
107 changes: 43 additions & 64 deletions lib/public_suffix/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def self.parse(input, private_domains: true)
next

else
list.add(Rule.factory(line, private: section == 2), reindex: false)
list.add(Rule.factory(line, private: section == 2))

end
end
Expand All @@ -103,32 +103,8 @@ def self.parse(input, private_domains: true)
# @yield [self] Yields on self.
# @yieldparam [PublicSuffix::List] self The newly created instance.
def initialize
@rules = []
@rules = {}
yield(self) if block_given?
reindex!
end


# Creates a naive index for +@rules+. Just a hash that will tell
# us where the elements of +@rules+ are relative to its first
# {PublicSuffix::Rule::Base#labels} element.
#
# For instance if @rules[5] and @rules[4] are the only elements of the list
# where Rule#labels.first is 'us' @indexes['us'] #=> [5,4], that way in
# select we can avoid mapping every single rule against the candidate domain.
def reindex!
@indexes = {}
@rules.each_with_index do |rule, index|
tld = Domain.name_to_labels(rule.value).last
@indexes[tld] ||= []
@indexes[tld] << index
end
end

# Gets the naive index, a hash that with the keys being the first label of
# every rule pointing to an array of integers (indexes of the rules in @rules).
def indexes
@indexes.dup
end


Expand All @@ -138,7 +114,7 @@ def indexes
# {PublicSuffix::List} and each +PublicSuffix::Rule::*+
# in list <tt>one</tt> is available in list <tt>two</tt>, in the same order.
#
# @param other [PublicSuffix::List] the List to compare
# @param other [PublicSuffix::List] the List to compare
# @return [Boolean]
def ==(other)
return false unless other.is_a?(List)
Expand All @@ -147,27 +123,26 @@ def ==(other)
alias eql? ==

# Iterates each rule in the list.
def each(*args, &block)
@rules.each(*args, &block)
def each(&block)
Enumerator.new do |y|
@rules.each do |key, node|
y << entry_to_rule(node, key)
end
end.each(&block)
end


# Adds the given object to the list and optionally refreshes the rule index.
#
# @see #reindex!
#
# @param rule [PublicSuffix::Rule::*] the rule to add to the list
# @param reindex [Boolean] Set to true to recreate the rule index
# after the rule has been added to the list.
# @return [self]
def add(rule, reindex: true)
@rules << rule
reindex! if reindex
def add(rule)
@rules[rule.value] = rule_to_entry(rule)
self
end
alias << add

# Gets the number of elements in the list.
# Gets the number of rules in the list.
#
# @return [Integer]
def size
Expand All @@ -181,34 +156,15 @@ def empty?
@rules.empty?
end

# Removes all elements.
# Removes all rules.
#
# @return [self]
def clear
@rules.clear
reindex!
self
end

# Finds and returns the most appropriate rule for the domain name.
#
# From the Public Suffix List documentation:
#
# - If a hostname matches more than one rule in the file,
# the longest matching rule (the one with the most levels) will be used.
# - An exclamation mark (!) at the start of a rule marks an exception to a previous wildcard rule.
# An exception rule takes priority over any other matching rule.
#
# ## Algorithm description
#
# 1. Match domain against all rules and take note of the matching ones.
# 2. If no rules match, the prevailing rule is "*".
# 3. If more than one rule matches, the prevailing rule is the one which is an exception rule.
# 4. If there is no matching exception rule, the prevailing rule is the one with the most labels.
# 5. If the prevailing rule is a exception rule, modify it by removing the leftmost label.
# 6. The public suffix is the set of labels from the domain
# which directly match the labels of the prevailing rule (joined by dots).
# 7. The registered domain is the public suffix plus one additional label.
# Finds and returns the rule corresponding to the longest public suffix for the hostname.
#
# @param name [#to_s] the hostname
# @param default [PublicSuffix::Rule::*] the default rule to return in case no rule matches
Expand All @@ -221,7 +177,7 @@ def find(name, default: default_rule, **options)
rule || default
end

# Selects all the rules matching given domain.
# Selects all the rules matching given hostame.
#
# If `ignore_private` is set to true, the algorithm will skip the rules that are flagged as
# private domain. Note that the rules will still be part of the loop.
Expand All @@ -239,12 +195,24 @@ def find(name, default: default_rule, **options)
# @return [Array<PublicSuffix::Rule::*>]
def select(name, ignore_private: false)
name = name.to_s
indices = (@indexes[Domain.name_to_labels(name).last] || [])

finder = @rules.values_at(*indices).lazy
finder = finder.select { |rule| rule.match?(name) }
finder = finder.select { |rule| !rule.private } if ignore_private
finder.to_a
parts = name.split(DOT).reverse!
index = 0
query = parts[index]
rules = []

loop do
match = @rules[query]
if !match.nil? && (ignore_private == false || match.private == false)
rules << entry_to_rule(match, query)
end

index += 1
break if index >= parts.size
query = parts[index] + DOT + query
end

rules
end
private :select

Expand All @@ -262,5 +230,16 @@ def default_rule

attr_reader :rules


private

def entry_to_rule(entry, value)
entry.type.new(value: value, length: entry.length, private: entry.private)
end

def rule_to_entry(rule)
Rule::Entry.new(rule.class, rule.length, rule.private)
end

end
end
55 changes: 35 additions & 20 deletions lib/public_suffix/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ module PublicSuffix
#
module Rule

# @api internal
Entry = Struct.new(:type, :length, :private)

# = Abstract rule class
#
# This represent the base class for a Rule definition
Expand Down Expand Up @@ -106,13 +109,21 @@ class Base
attr_reader :private


# Initializes a new rule with name and value.
# If value is +nil+, name also becomes the value for this rule.
# Initializes a new rule from the content.
#
# @param content [String] the content of the rule
# @param private [Boolean]
def self.build(content, private: false)
new(value: content, private: private)
end

# Initializes a new rule.
#
# @param value [String] the value of the rule
def initialize(value, private: false)
# @param value [String]
# @param private [Boolean]
def initialize(value:, length: nil, private: false)
@value = value.to_s
@length = @value.count(DOT) + 1
@length = length || @value.count(DOT) + 1
@private = private
end

Expand Down Expand Up @@ -204,15 +215,21 @@ def parts
# Wildcard represents a wildcard rule (e.g. *.co.uk).
class Wildcard < Base

# Initializes a new rule from +definition+.
# Initializes a new rule from the content.
#
# The wildcard "*" is removed from the value,
# as it's common for each wildcard rule.
# @param content [String] the content of the rule
# @param private [Boolean]
def self.build(content, private: false)
new(value: content.to_s[2..-1], private: private)
end

# Initializes a new rule.
#
# @param definition [String] the rule as defined in the PSL
def initialize(definition, private: false)
super(definition.to_s[2..-1], private: private)
@length += 1 # * counts as 1
# @param value [String]
# @param private [Boolean]
def initialize(value:, length: nil, private: false)
super(value: value, length: length, private: private)
length or @length += 1 # * counts as 1
end

# Gets the original rule definition.
Expand Down Expand Up @@ -245,14 +262,12 @@ def parts
# Exception represents an exception rule (e.g. !parliament.uk).
class Exception < Base

# Initializes a new rule from +definition+.
#
# The bang ! is removed from the value,
# as it's common for each exception rule.
# Initializes a new rule from the content.
#
# @param definition [String] the rule as defined in the PSL
def initialize(definition, private: false)
super(definition.to_s[1..-1], private: private)
# @param content [String] the content of the rule
# @param private [Boolean]
def self.build(content, private: false)
new(value: content.to_s[1..-1], private: private)
end

# Gets the original rule definition.
Expand Down Expand Up @@ -314,7 +329,7 @@ def self.factory(content, private: false)
Exception
else
Normal
end.new(content, private: private)
end.build(content, private: private)
end

# The default rule to use if no rule match.
Expand Down
2 changes: 1 addition & 1 deletion public_suffix.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.description = "PublicSuffix can parse and decompose a domain name into top level domain, domain and subdomains."
s.licenses = ["MIT"]

s.required_ruby_version = ">= 2.0"
s.required_ruby_version = ">= 2.1"

s.require_paths = ["lib"]
s.files = `git ls-files`.split("\n")
Expand Down
2 changes: 2 additions & 0 deletions test/.empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is an empty file I use to force a non-empty commit when I only need to store notes
..
Loading