summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2024-01-12 15:37:38 +0100
committerNeal H. Walfield <neal@pep.foundation>2024-01-12 15:37:38 +0100
commitce5fed53d9cf58f54f95f6a87e8fcac7b2b63b55 (patch)
treecc64c6844ba7b088335d9bc7102b8dee83cf80c3
parentcaabbbdb867bbefddcc17deea79cf8986348a500 (diff)
openpgp: Wrap bare email addresses in angle brackets.
- Change `UserID::from_address` to wrap a bare address in angle brackets. That is, change `UserID::from_address` so that `UserID::from_address(None, None, "alice@example.org")` maps to `<alice@example.org>` not `alice@example.org`. This has the advantage that the standard regular expression for scoping CAs can match bare email addresses, see: https://docs.sequoia-pgp.org/sequoia_openpgp/regex/index.html#caveat-emptor - Fixes #1076.
-rw-r--r--openpgp/src/packet/userid.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs
index 4a1a6016..0b8b0ae6 100644
--- a/openpgp/src/packet/userid.rs
+++ b/openpgp/src/packet/userid.rs
@@ -657,14 +657,12 @@ impl UserID {
}
}
- let something = !value.is_empty();
- if something {
- value.push_str(" <");
+ if !value.is_empty() {
+ value.push(' ');
}
+ value.push('<');
value.push_str(address);
- if something {
- value.push('>');
- }
+ value.push('>');
if check_address {
// Make sure the combined thing is valid.
@@ -1315,7 +1313,7 @@ mod tests {
Some("First Last"), Some("Comment"), Some("name@example.org"), None);
c("First Last <name@example.org>",
Some("First Last"), None, Some("name@example.org"), None);
- c("name@example.org",
+ c("<name@example.org>",
None, None, Some("name@example.org"), None);
}
@@ -1411,7 +1409,7 @@ mod tests {
fn from_address() {
assert_eq!(UserID::from_address(None, None, "foo@bar.com")
.unwrap().value(),
- b"foo@bar.com");
+ b"<foo@bar.com>");
assert!(UserID::from_address(None, None, "foo@@bar.com").is_err());
assert_eq!(UserID::from_address("Foo Q. Bar".into(), None, "foo@bar.com")
.unwrap().value(),