Skip to content

Commit

Permalink
Fix Contact strictness
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Oct 24, 2024
1 parent 458a519 commit 33bec76
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyproject-toml"
version = "0.13.1"
version = "0.13.2"
description = "pyproject.toml parser in Rust"
edition = "2021"
license = "MIT"
Expand Down
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.13.2

* Make `Contact` definition strict

## 0.13.1

* Fix `Contact` definition

## 0.13.0

* Update to the provisional PEP 639. This is technically a breaking change, but only for fields previously in draft
Expand Down
34 changes: 31 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,19 @@ pub enum License {
/// The entry is derived from the email format of `John Doe <[email protected]>`. You need to
/// provide at least name or email.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged, expecting = "a table with 'name' and/or 'email' keys")]
// deny_unknown_fields prevents using the name field when the email is not a string.
#[serde(
untagged,
deny_unknown_fields,
expecting = "a table with 'name' and/or 'email' keys"
)]
pub enum Contact {
/// TODO(konsti): RFC 822 validation.
NameEmail { name: String, email: String },
/// TODO(konsti): RFC 822 validation.
Name { name: String },
/// TODO(konsti): RFC 822 validation.
Email { email: String },
/// TODO(konsti): RFC 822 validation.
NameEmail { name: String, email: String },
}

/// The `[dependency-groups]` section of pyproject.toml, as specified in PEP 735
Expand Down Expand Up @@ -475,4 +480,27 @@ iota = [{include-group = "alpha"}]
}]
);
}

#[test]
fn invalid_email() {
let source = r#"
[project]
name = "hello-world"
version = "0.1.0"
# Ensure that the spans from toml handle utf-8 correctly
authors = [
{ name = "Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘", email = 1 }
]
"#;
let err = PyProjectToml::new(source).unwrap_err();
assert_eq!(
err.to_string(),
"TOML parse error at line 6, column 11
|
6 | authors = [
| ^
a table with 'name' and/or 'email' keys
"
);
}
}

0 comments on commit 33bec76

Please sign in to comment.