Skip to content

Commit

Permalink
feat: adding unicode support RFC6532
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayan751 committed Sep 4, 2020
1 parent 897b78d commit 5d1f60e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 62 deletions.
2 changes: 1 addition & 1 deletion rust-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ macro_rules! generate_is_valid_test {
#[test]
#[wasm_bindgen_test]
fn $case() {
assert_eq!(EmailAddress::is_valid(&$address, None), $is_valid, \"expected {} not to be valid: {}\", $address, $is_valid);
assert_eq!(EmailAddress::is_valid(&$address, None), $is_valid, \"expected {} to be valid: {}\", $address, $is_valid);
}
)*
}
Expand Down
56 changes: 0 additions & 56 deletions rust-lib/resources/.test_data/idns.txt

This file was deleted.

32 changes: 31 additions & 1 deletion rust-lib/resources/.test_data/valid_domains.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,34 @@ xn--masekowski-d0b.pl
[192.168.0.1]
[1.2.3.4]
[0.0.0.1]
[255.255.255.254]
[255.255.255.254]
masełkowski.pl.com
中国互联网络信息中心.中国
中国互联网络信息中心.xn--masekowski-d0b
bücher.com
nächste.de
löwen.de
افغانستا.com
বাংলাদেশ.com
беларусь.com
belgië.com
českárepublika.com
مصر.com
ελλάδα.com
ísland.com
भारत.com
איקו״ם.ישראל.com
қазақстан.com
한국.com
кыргызстан.com
ລາວ.com
македонија.com
монголулс.com
россия.иком.com
இலங்கை.com
españa.com
ไทย.com
việtnam.com
📻.fm
🎁.de
âêîôû.Çéàèù.ëïü
Binary file added rust-lib/resources/rfc6532.pdf
Binary file not shown.
9 changes: 8 additions & 1 deletion rust-lib/src/email_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Default for ParsingOptions {
fn default() -> Self {
ParsingOptions {
is_lax: false,
supports_unicode: false,
supports_unicode: true,
}
}
}
Expand Down Expand Up @@ -364,4 +364,11 @@ mod tests {
println!("{:#?}", actual);
assert_eq!(actual.is_err(), false);
}

#[test]
fn can_parse_idn() {
let actual = RFC5322::parse(Rule::domain_complete, "bücher.com");
println!("{:#?}", actual);
assert_eq!(actual.is_err(), false);
}
}
15 changes: 12 additions & 3 deletions rust-lib/src/rfc5322.pest
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ FWS = _{ ((WSP* ~ CRLF)? ~ WSP+) | obs_FWS }
DQUOTE = { "\"" }
quoted_pair = { ("\\" ~ (printable_us_ascii | WSP)) | obs_qp }
// Printable US-ASCII characters not including "(", ")", or "\".
ctext = { !("(" | ")" | "\\") ~ (printable_us_ascii | obs_ctext) }
ctext = { !("(" | ")" | "\\") ~ (printable_us_ascii | UTF8_non_ascii | obs_ctext) }
ccontent = { ctext | quoted_pair | comment }
comment = { "(" ~ (FWS? ~ ccontent)* ~ FWS? ~ ")" }
CFWS = _{ ((FWS? ~ comment)+ ~ FWS?) | FWS }

atext = { ASCII_ALPHANUMERIC
| "!" | "#" |"$" | "%" | "&" | "'" |"*" | "+" |"-" | "/" |"=" | "?" |"^" | "_" |"`" | "{" |"|" | "}" |"~"
| UTF8_non_ascii
}

/*------------ UTF8 START -------------*/
UTF8_2 = { '\u{80}'..'\u{7FF}' }
UTF8_3 = { '\u{800}'..'\u{FFFF}' }
UTF8_4 = { '\u{10000}'..'\u{10FFFF}' }
UTF8_non_ascii = { UTF8_2 | UTF8_3 | UTF8_4 }
/*------------ UTF8 END -------------*/

/**
* The construction dot_atom_text rule is an intentional deviation from the RFC5322.
* The original rule is `{ atext+ ("." ~ atext+)* }`.
Expand All @@ -43,11 +52,11 @@ dot_atom_text = {
dot_atom = { WSP? ~ dot_atom_text ~ WSP? }

// Printable US-ASCII characters not including "[", "]", or "\".
dtext = { !("[" | "]" | "\\") ~ (printable_us_ascii | obs_dtext) }
dtext = { !("[" | "]" | "\\") ~ (printable_us_ascii | UTF8_non_ascii | obs_dtext) }
domain_literal = { CFWS? ~ "[" ~ (FWS? ~ dtext)* ~ FWS? ~ "]" ~ CFWS? }

// Printable US-ASCII characters not including "\" or the quote character.
qtext = { !(DQUOTE | "\\" ) ~ (printable_us_ascii | obs_qtext) }
qtext = { !(DQUOTE | "\\" ) ~ (printable_us_ascii | UTF8_non_ascii | obs_qtext) }
qcontent = { qtext | quoted_pair }
quoted_string = { CFWS? ~ DQUOTE ~ (FWS? ~ qcontent)* ~ FWS? ~ DQUOTE ~ CFWS? }

Expand Down

0 comments on commit 5d1f60e

Please sign in to comment.