Repository navigation
Add prevailing_rule/2 and matches_explicit_rule?/1 - #17
Conversation
| |> String.split(".") | ||
| |> find_prevailing_rule(options) | ||
| |> Enum.join(".") | ||
| end |
There was a problem hiding this comment.
I think it's confusing to overload parse_domain to do entirely separate things based on the flag provided as the last argument. Instead, WDYT about removing the last arg to parse_domain and inlining this logic in prevailing_rule/2?
400c9f3 to
7520462
Compare
|
Alright, should be better now. I did a few slight modifications to make |
7520462 to
e88871d
Compare
| @exact_match_rules[domain_labels] in allowed_rule_types -> {:normal, domain_labels} | ||
| # TODO: "Wildcards are not restricted to appear only in the leftmost position" | ||
| @wild_card_rules[["*" | suffix]] in allowed_rule_types -> domain_labels | ||
| @wild_card_rules[["*" | suffix]] in allowed_rule_types -> {:normal, ["*"] ++ suffix} |
There was a problem hiding this comment.
I recommend using ["*" | suffix] over ["*"] ++ suffix. The ++ operator is O(n) over the size of the list on the left, whereas [a | b] is highly optimized and is always constant time.
In this case, the list of the left has only one element so I doubt there's a perf difference, but as a a matter of habit I think it's best to prefer the [a | b] form when it can be used, as it can here.
|
Well done @andersju! I left a few suggestions but this LGTM otherwise. |
same; make find_prevailing_rule return actual matching rule; update README
e88871d to
fbbcacd
Compare
|
@myronmarston: I fixed the last few things you mentioned. Thanks for the feedback, very helpful! |
|
LGTM. Thanks, @andersju! |
This fixes #15 by adding
prevailing_rule/2(returns prevailing rule of domain) andmatches_explicit_rule?(checks whether domain matches explicit rule). E.g.:Tests also added.
prevailing_ruleis tested intest/generated_test_cases.exs. It should return the same aspublic_suffix, except for a few cases (e.g. when the domain is unlisted) where it should return"*"; these are handled separately intest/public_suffix_test.exs, where there are also some tests formatches_explicit_rule?.(Disclaimer: I'd never touched ExUnit before but I think it's OK :))