summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2022-07-06 15:22:40 +0200
committerNeal H. Walfield <neal@pep.foundation>2022-07-06 15:25:39 +0200
commit3e95c56ee010d91968d23df1e5eafbce601803b5 (patch)
treee6abd2dac0c2637e866299a25e1284952f531e14
parenta0c0b65360f6905eb1bf0e2b9ce540f27c78b525 (diff)
openpgp: Fix parsing of dashes in regular expressions.
- When a dash occurs outside of a range, it should be considered an atom. - Fixes #897.
-rw-r--r--openpgp/src/regex/grammar.lalrpop4
-rw-r--r--openpgp/src/regex/mod.rs36
2 files changed, 40 insertions, 0 deletions
diff --git a/openpgp/src/regex/grammar.lalrpop b/openpgp/src/regex/grammar.lalrpop
index 46fd7a70..fccd84f8 100644
--- a/openpgp/src/regex/grammar.lalrpop
+++ b/openpgp/src/regex/grammar.lalrpop
@@ -129,6 +129,10 @@ Atom : Hir = {
hir::Hir::literal(hir::Literal::Unicode(t.to_char()))
},
+ DASH => {
+ hir::Hir::literal(hir::Literal::Unicode('-'))
+ },
+
<t:OTHER> => {
hir::Hir::literal(hir::Literal::Unicode(t.to_char()))
},
diff --git a/openpgp/src/regex/mod.rs b/openpgp/src/regex/mod.rs
index f42009a7..e2176952 100644
--- a/openpgp/src/regex/mod.rs
+++ b/openpgp/src/regex/mod.rs
@@ -1986,6 +1986,24 @@ mod tests {
(true, "c"),
]);
+ // Make sure - is recognized as an atom when it is not part of
+ // a range. That is: a-z matches a or - or z, but it doesn't
+ // match b (it's not a range).
+ a("a-z", &[
+ (true, "a-z"),
+ (false, "a"),
+ (false, "-"),
+ (false, "z"),
+ (false, "c"),
+ ]);
+
+ a("a|-|z", &[
+ (true, "a"),
+ (true, "-"),
+ (true, "z"),
+ (false, "c"),
+ ]);
+
Ok(())
}
@@ -2036,4 +2054,22 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn regex_set_sequoia() -> Result<()> {
+ let re = RegexSet::new(&["<[^>]+[@.]sequoia-pgp\\.org>$"])?;
+ dbg!(&re);
+ assert!(re.is_match("<justus@sequoia-pgp.org>"));
+ assert!(!re.is_match("<justus@gnupg.org>"));
+ Ok(())
+ }
+
+ #[test]
+ fn regex_set_sequoia_nodash() -> Result<()> {
+ let re = RegexSet::new(&["<[^>]+[@.]sequoiapgp\\.org>$"])?;
+ dbg!(&re);
+ assert!(re.is_match("<justus@sequoiapgp.org>"));
+ assert!(!re.is_match("<justus@gnupg.org>"));
+ Ok(())
+ }
}