git.delta.rocks / unique-network / refs/commits / 599b5140ca91

difftreelog

Fix check_property_key

Daniel Shiposha2022-05-12parent: #579ff14.patch.diff
in: master

2 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -377,6 +377,9 @@
 
 		/// Only ASCII letters, digits, and '_', '-' are allowed
 		InvalidCharacterInPropertyKey,
+
+		/// Empty property keys are forbidden
+		EmptyPropertyKey,
 	}
 
 	#[pallet::storage]
@@ -1226,6 +1229,7 @@
 			PropertiesError::NoSpaceForProperty => Self::NoSpaceForProperty,
 			PropertiesError::PropertyLimitReached => Self::PropertyLimitReached,
 			PropertiesError::InvalidCharacterInPropertyKey => Self::InvalidCharacterInPropertyKey,
+			PropertiesError::EmptyPropertyKey => Self::EmptyPropertyKey,
 		}
 	}
 }
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
683 NoSpaceForProperty,683 NoSpaceForProperty,
684 PropertyLimitReached,684 PropertyLimitReached,
685 InvalidCharacterInPropertyKey,685 InvalidCharacterInPropertyKey,
686 EmptyPropertyKey,
686}687}
687688
688pub trait TrySet: Sized {689pub trait TrySet: Sized {
728 }729 }
729730
730 fn check_property_key(key: &PropertyKey) -> Result<(), PropertiesError> {731 fn check_property_key(key: &PropertyKey) -> Result<(), PropertiesError> {
731 let key_str = sp_std::str::from_utf8(key.as_slice())732 if key.is_empty() {
732 .map_err(|_| PropertiesError::InvalidCharacterInPropertyKey)?;733 return Err(PropertiesError::EmptyPropertyKey);
734 }
733735
734 for ch in key_str.chars() {736 for byte in key.as_slice().iter() {
737 match char::from_u32(*byte as u32) {
738 Some(ch)
735 if !ch.is_ascii_alphanumeric() && ch != '_' && ch != '-' {739 if ch.is_ascii_alphanumeric()
740 || ch == '_'
741 || ch == '-' => { /* OK */ },
736 return Err(PropertiesError::InvalidCharacterInPropertyKey);742 _ => return Err(PropertiesError::InvalidCharacterInPropertyKey)
737 }743 }
738 }744 }
739745
740 Ok(())746 Ok(())