From bf5514c0247a07e3351358884426b7749e0de049 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 15 Feb 2022 10:33:57 +0100 Subject: [PATCH] Ensure that author preamble has handle or email --- src/error.rs | 2 + src/validators.rs | 4 ++ tests/fixtures/preamble-author-no-contact.md | 39 ++++++++++++++++++++ tests/tests.rs | 4 ++ 4 files changed, 49 insertions(+) create mode 100644 tests/fixtures/preamble-author-no-contact.md diff --git a/src/error.rs b/src/error.rs index 113c991..cec00b4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -40,6 +40,7 @@ pub enum Error { UnmatchedEmailDelimiter, UnmatchedHandleDelimiter, AuthorHasEmailAndHandle, + AuthorHasNoContactDetails, TrailingInfoAfterEmail, TrailingInfoAfterHandle, MalformedEmail, @@ -98,6 +99,7 @@ impl Error { Self::UnmatchedEmailDelimiter => "unmatched email delimiter", Self::UnmatchedHandleDelimiter => "unmatched handle delimiter", Self::AuthorHasEmailAndHandle => "author can't include both an email and handle", + Self::AuthorHasNoContactDetails => "author has no contact details", Self::TrailingInfoAfterEmail => "trailing information after email", Self::TrailingInfoAfterHandle => "trailing information after handle", Self::MalformedEmail => "malformed email", diff --git a/src/validators.rs b/src/validators.rs index 9b238e7..46d9157 100644 --- a/src/validators.rs +++ b/src/validators.rs @@ -141,6 +141,10 @@ fn validate_author<'a>(acc: &mut Vec, s: &str) -> Result<()> { return Err(Error::AuthorHasEmailAndHandle); } + if email_start.is_some() == false && handle_start.is_some() == false { + return Err(Error::AuthorHasNoContactDetails); + } + if email_start.is_some() { let start = email_start.unwrap(); let end = email_end.unwrap(); diff --git a/tests/fixtures/preamble-author-no-contact.md b/tests/fixtures/preamble-author-no-contact.md new file mode 100644 index 0000000..dd4b3ab --- /dev/null +++ b/tests/fixtures/preamble-author-no-contact.md @@ -0,0 +1,39 @@ +--- +eip: 1 +title: A sample proposal +author: John Doe +discussions-to: https://example.com +status: Draft +type: Standards Track +category: Core +created: 2020-01-01 +updated: 2020-01-01 +requires: 20, 1337, 2048 +--- + +## Abstract +This is the abstract for the EIP. + +## Motivation +This is the motivation for the EIP. + +## Specification +This is the specification for the EIP. + +## Rationale +This is the rationale for the EIP. + +## Backwards Compatibility +These are the backwards compatibility concerns for the EIP. + +## Test Cases +These are the test cases for the EIP. + +## Implementation +This is the implementation for the EIP. + +## Security Considerations +These are the security considerations for the EIP. + +## Copyright +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). diff --git a/tests/tests.rs b/tests/tests.rs index 729a8cb..7ccfacd 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -158,6 +158,10 @@ fn preamble_author() { ); test_fixture("preamble-author-email-invalid.md", "malformed email"); test_fixture("preamble-author-handle-invalid.md", "malformed handle"); + test_fixture( + "preamble-author-no-contact.md", + "author has no contact details", + ); } #[test]