diff --git a/src/lib.rs b/src/lib.rs index 247fcd2..6c9c864 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,22 +11,26 @@ // specific language governing permissions and limitations under // each license. -#![deny(warnings)] +#![deny(clippy::expect_used)] +#![deny(clippy::panic)] +#![deny(clippy::unwrap_used)] #![deny(missing_docs)] +#![deny(warnings)] #![doc = include_str!("../README.md")] mod ffi; - -#[cfg(test)] -mod tests; - mod xmp_date_time; mod xmp_error; mod xmp_file; mod xmp_meta; pub mod xmp_ns; -pub use xmp_date_time::XmpDateTime; -pub use xmp_error::{XmpError, XmpErrorType, XmpResult}; -pub use xmp_file::{OpenFileOptions, XmpFile}; -pub use xmp_meta::XmpMeta; +pub use { + xmp_date_time::XmpDateTime, + xmp_error::{XmpError, XmpErrorType, XmpResult}, + xmp_file::{OpenFileOptions, XmpFile}, + xmp_meta::XmpMeta, +}; + +#[cfg(test)] +mod tests; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index a4e5865..689862d 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -14,6 +14,10 @@ // Tests are grouped under this module so as to avoid // having the test code itself included in coverage numbers. +#![allow(clippy::expect_used)] +#![allow(clippy::panic)] +#![allow(clippy::unwrap_used)] + mod fixtures; mod xmp_date_time; mod xmp_error; diff --git a/src/tests/xmp_meta.rs b/src/tests/xmp_meta.rs index c46ba64..6bd1a76 100644 --- a/src/tests/xmp_meta.rs +++ b/src/tests/xmp_meta.rs @@ -110,6 +110,18 @@ mod property { let m = XmpMeta::from_file(fixture_path("Purple Square.psd")).unwrap(); assert_eq!(m.property(xmp_ns::XMP, ""), None); } + + #[test] + fn invalid_namespace() { + let m = XmpMeta::from_file(fixture_path("Purple Square.psd")).unwrap(); + assert_eq!(m.property("\0", "CreatorTool"), None); + } + + #[test] + fn invalid_prop_name() { + let m = XmpMeta::from_file(fixture_path("Purple Square.psd")).unwrap(); + assert_eq!(m.property(xmp_ns::XMP, "\0"), None); + } } mod set_property { diff --git a/src/xmp_meta.rs b/src/xmp_meta.rs index 0a1cab4..3e82efe 100644 --- a/src/xmp_meta.rs +++ b/src/xmp_meta.rs @@ -11,13 +11,14 @@ // specific language governing permissions and limitations under // each license. -use std::{ - ffi::{CStr, CString}, - path::Path, +use { + crate::{ffi, OpenFileOptions, XmpDateTime, XmpError, XmpErrorType, XmpFile, XmpResult}, + std::{ + ffi::{CStr, CString}, + path::Path, + }, }; -use crate::{ffi, OpenFileOptions, XmpDateTime, XmpError, XmpErrorType, XmpFile, XmpResult}; - /// The `XmpMeta` struct allows access to the XMP Toolkit core services. /// /// You can create `XmpMeta` structs from metadata that you construct, @@ -124,8 +125,8 @@ impl XmpMeta { /// Any errors (for instance, empty or invalid namespace or property name) /// are ignored; the function will return `None` in such cases. pub fn property(&self, schema_ns: &str, prop_name: &str) -> Option { - let c_ns = CString::new(schema_ns).unwrap(); - let c_name = CString::new(prop_name).unwrap(); + let c_ns = CString::new(schema_ns).unwrap_or_default(); + let c_name = CString::new(prop_name).unwrap_or_default(); unsafe { let c_result = ffi::CXmpMetaGetProperty(self.m, c_ns.as_ptr(), c_name.as_ptr());