Skip to content

Commit

Permalink
Merge pull request fcsonline#8 from Emantor/topic/ipv6
Browse files Browse the repository at this point in the history
Add ipv6 matching support
  • Loading branch information
fcsonline authored Jun 20, 2019
2 parents 3f1c9aa + aaf0b3c commit f1123d6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt;
const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] =
[("bash", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")];

const PATTERNS: [(&'static str, &'static str); 11] = [
const PATTERNS: [(&'static str, &'static str); 12] = [
("markdown_url", r"\[[^]]*\]\(([^)]+)\)"),
(
"url",
Expand All @@ -21,6 +21,7 @@ const PATTERNS: [(&'static str, &'static str); 11] = [
),
("sha", r"[0-9a-f]{7,40}"),
("ip", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"),
("ipv6", r"[A-f0-9:]+:+[A-f0-9:]+[%\w\d]+"),
("address", r"0x[0-9a-fA-F]+"),
("number", r"[0-9]{4,}"),
];
Expand Down Expand Up @@ -272,6 +273,25 @@ mod tests {
assert_eq!(results.get(2).unwrap().text.clone(), "127.0.0.1");
}

#[test]
fn match_ipv6s() {
let lines = split("Lorem ipsum fe80::2:202:fe4 lorem\n Lorem 2001:67c:670:202:7ba8:5e41:1591:d723 lorem fe80::2:1 lorem ipsum fe80:22:312:fe::1%eth0");
let custom = [].to_vec();
let results = State::new(&lines, "abcd", &custom).matches(false, false);

assert_eq!(results.len(), 4);
assert_eq!(results.get(0).unwrap().text.clone(), "fe80::2:202:fe4");
assert_eq!(
results.get(1).unwrap().text.clone(),
"2001:67c:670:202:7ba8:5e41:1591:d723"
);
assert_eq!(results.get(2).unwrap().text.clone(), "fe80::2:1");
assert_eq!(
results.get(3).unwrap().text.clone(),
"fe80:22:312:fe::1%eth0"
);
}

#[test]
fn match_markdown_urls() {
let lines =
Expand Down

0 comments on commit f1123d6

Please sign in to comment.