diff --git a/Cargo.lock b/Cargo.lock index 33fca6f..678b840 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,7 @@ dependencies = [ [[package]] name = "pyproject-toml" -version = "0.13.1" +version = "0.13.2" dependencies = [ "glob", "indexmap", diff --git a/Cargo.toml b/Cargo.toml index b2e6d8b..763756a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/Changelog.md b/Changelog.md index 1fba272..ed0fdaf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 027d32c..b58c88e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,14 +162,19 @@ pub enum License { /// The entry is derived from the email format of `John Doe `. 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 @@ -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 +" + ); + } }