rushmorem / publicsuffix

An implementation of Mozilla's Public Suffix List in Rust
MIT License
96 stars 17 forks source link

Exclusion rules are not implemented correctly #25

Closed dead10ck closed 4 years ago

dead10ck commented 4 years ago

At the time of this writing, the public suffix list contains the rules

*.ck
!www.ck

So with these rules e.g. foo.www.ck is an invalid domain because it does not have a valid suffix. However, the code produces this parse result:

[src/main.rs:46] list.parse_domain("foo.www.ck") = Ok(
    Domain {
        full: "foo.www.ck",
        typ: Some(
            Icann,
        ),
        suffix: Some(
            "ck",
        ),
        registrable: Some(
            "www.ck",
        ),
    },
)

which is incorrect, because ck is not a valid suffix on its own (it needs one label in front of it, and it can't be www).

You see a similar issue with other exclusion rules, e.g.

[src/main.rs:46] list.parse_domain("foo.city.kawasaki.jp") = Ok(
    Domain {
        full: "foo.city.kawasaki.jp",
        typ: Some(
            Icann,
        ),
        suffix: Some(
            "kawasaki.jp",
        ),
        registrable: Some(
            "city.kawasaki.jp",
        ),
    },
)

It seems when evaluating exclusion rules, the code presently seems to just strip off the first label and say that's the suffix. If I'm not mistaken, the correct thing to do here is just return an error that indicates the input domain is invalid.

dead10ck commented 4 years ago

Sorry, please disregard this; I did not understand how the exclusion rules worked. I see you implemented the algorithm as described on the web page.