rushmorem / publicsuffix

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

Question: Single label domain and suffix #10

Closed jonasbb closed 7 years ago

jonasbb commented 7 years ago

As mentioned in https://github.com/rushmorem/publicsuffix/issues/8 there is an inconsistency between the handling of registered single label domains and unregistered ones. Namely, only suffixes which do appear in the publicsuffixlist are parsed into a suffix and and empty registrable.

// Domain { full: "com", typ: Some(Icann), suffix: Some("com"), registrable: None }
eprintln!("{:?}", list.parse_domain("com").unwrap());
// Domain { full: "localhost", typ: None, suffix: None, registrable: None }
eprintln!("{:?}", list.parse_domain("localhost").unwrap());

If we look at two-label domains, this is different:

// Domain { full: "test.com.", typ: None, suffix: Some("com"), registrable: Some("test.com") }
eprintln!("{:?}", list.parse_domain("test.com.").unwrap());
// Domain { full: "test.localhost.", typ: None, suffix: Some("localhost"), registrable: Some("test.localhost") }
eprintln!("{:?}", list.parse_domain("test.localhost.").unwrap());

The code which fills the suffix and registrable in the second case is lines 645-648. I assume this is to try to give as much information as possible for suffixes which are not in the list (maybe because the list is outdated).

Would it make sense to add a case like

else if suffix.is_none() && d_labels.len() == 1 && no_possible_matches_found {
    suffix = Some(Self::assemble(input, 1));
    registrable = None;
}

to make the handling of single-label domains more uniform?

rushmorem commented 7 years ago

Yes, indeed. Kindly submit a pull request if you have enough time to do this. If not, just let me know. Thanks!

rushmorem commented 7 years ago

Fixed by https://github.com/rushmorem/publicsuffix/pull/12.