Skip to content

Commit

Permalink
Add List::empty() to allow creating an empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
rushmorem committed Jan 5, 2017
1 parent 583765e commit 39f511f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "publicsuffix"
description = "A robust and reliable library for parsing domain names"
version = "1.3.1"
description = "Robust domain name parsing and RFC compliant email address validation"
version = "1.3.2"
license = "MIT/Apache-2.0"
repository = "https://github.com/rushmorem/publicsuffix"
documentation = "https://docs.rs/publicsuffix"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# A Rust library for robust domain name parsing
# Robust domain name parsing and RFC compliant email address validation

[![Build Status](https://travis-ci.org/rushmorem/publicsuffix.svg?branch=master)](https://travis-ci.org/rushmorem/publicsuffix) [![Latest Version](https://img.shields.io/crates/v/publicsuffix.svg)](https://crates.io/crates/publicsuffix) [![Docs](https://docs.rs/publicsuffix/badge.svg)](https://docs.rs/publicsuffix)

This library uses Mozilla's [Public Suffix List](https://publicsuffix.org) to reliably parse domain names in [Rust](https://www.rust-lang.org). Though parsing domain names is it's primary goal, it also fully exposes the list allowing you to use convenient methods like `list.all()` to get all known domain extensions or `list.icann()` to get only ICANN extensions.
This library uses Mozilla's [Public Suffix List](https://publicsuffix.org) to reliably parse domain names and email addresses in [Rust](https://www.rust-lang.org). Though parsing domain names is it's primary goal, it also fully exposes the list allowing you to use convenient methods like `list.all()` to get all known domain extensions or `list.icann()` to get only ICANN extensions.

If all you need is to check whether a domain is syntactically correct and do not need to utilise the list you can just use `Domain::has_valid_syntax` method. This method will reliably tell you if a domain has valid syntax whether or not it is an internationalised domain name (IDN). It also checks the length restrictions for each label, total number of labels and full length of domain name.

Expand Down
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ impl List {

fn build(res: String) -> Result<List> {
let mut typ = None;
let mut list = List {
rules: HashMap::new(),
};
let mut list = List::empty();
for line in res.lines() {
match line {
line if line.contains("BEGIN ICANN DOMAINS") => { typ = Some(Type::Icann); }
Expand All @@ -294,6 +292,17 @@ impl List {
Ok(list)
}

/// Creates an empty List without any rules
///
/// Sometimes all you want is to do syntax checks. If you don't really care whether
/// the domain has a known suffix or not you can just create an empty list and use
/// that to parse domain names and email addresses.
pub fn empty() -> List {
List {
rules: HashMap::new(),
}
}

/// Pull the list from a URL
#[cfg(feature = "remote_list")]
pub fn from_url<U: IntoUrl>(url: U) -> Result<List> {
Expand Down

0 comments on commit 39f511f

Please sign in to comment.