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
378 /// Only ASCII letters, digits, and '_', '-' are allowed378 /// Only ASCII letters, digits, and '_', '-' are allowed
379 InvalidCharacterInPropertyKey,379 InvalidCharacterInPropertyKey,
380
381 /// Empty property keys are forbidden
382 EmptyPropertyKey,
380 }383 }
381384
382 #[pallet::storage]385 #[pallet::storage]
1226 PropertiesError::NoSpaceForProperty => Self::NoSpaceForProperty,1229 PropertiesError::NoSpaceForProperty => Self::NoSpaceForProperty,
1227 PropertiesError::PropertyLimitReached => Self::PropertyLimitReached,1230 PropertiesError::PropertyLimitReached => Self::PropertyLimitReached,
1228 PropertiesError::InvalidCharacterInPropertyKey => Self::InvalidCharacterInPropertyKey,1231 PropertiesError::InvalidCharacterInPropertyKey => Self::InvalidCharacterInPropertyKey,
1232 PropertiesError::EmptyPropertyKey => Self::EmptyPropertyKey,
1229 }1233 }
1230 }1234 }
1231}1235}
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(())