addr-rs / addr

Parse domain names reliably and quickly in Rust
MIT License
51 stars 12 forks source link

Document the difference between domain names and DNS names #10

Closed rusty-snake closed 3 years ago

rusty-snake commented 3 years ago

Old issue: rushmorem/publicsuffix#33

My test program outputs domain contains illegal characters. But if you replace the _ with a -, it outputs sub-domain.example.com.

src/main.rs:

use addr::parser::DomainName;
use psl::List;

fn main() {
    match List.parse_domain_name("sub_domain.example.com") {
        Ok(ok) => println!("{}", ok),
        Err(err) => println!("{}", err),
    }
}

Cargo.local:

[package]
name = "adr"
version = "0.1.0"
authors = ["rusty-snake"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
addr = "0.11"
psl = "2.0"
rushmorem commented 3 years ago

That's by design. Try parse_dns_name instead.

use addr::parser::DnsName;
use psl::List;

fn main() {
    match List.parse_dns_name("sub_domain.example.com") {
        Ok(ok) => println!("{}", ok),
        Err(err) => println!("{}", err),
    }
}
rusty-snake commented 3 years ago

Ahh, ok that works. Then needs the differences between dns name and domain name better documentation.

rushmorem commented 3 years ago

Yeah, sure. Let's leave this open for now until such documentation is in place.