Skip to content
Snippets Groups Projects

stricter idty name validation

Merged Pascal Engélibert requested to merge idty-name-validation into master
2 files
+ 23
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 14
1
@@ -83,7 +83,20 @@ impl<Runtime: pallet_babe::Config> frame_support::pallet_prelude::Get<u64>
@@ -83,7 +83,20 @@ impl<Runtime: pallet_babe::Config> frame_support::pallet_prelude::Get<u64>
pub struct IdtyNameValidatorImpl;
pub struct IdtyNameValidatorImpl;
impl pallet_identity::traits::IdtyNameValidator for IdtyNameValidatorImpl {
impl pallet_identity::traits::IdtyNameValidator for IdtyNameValidatorImpl {
 
// Bound length; forbid trailing or double spaces; accept only ascii alphanumeric or punctuation or space
fn validate(idty_name: &pallet_identity::IdtyName) -> bool {
fn validate(idty_name: &pallet_identity::IdtyName) -> bool {
idty_name.0.len() >= 3 && idty_name.0.len() <= 64
idty_name.0.len() >= 3
 
&& idty_name.0.len() <= 64
 
&& idty_name.0[0] != 32
 
&& idty_name.0[idty_name.0.len() - 1] != 32
 
&& idty_name
 
.0
 
.iter()
 
.all(|c| c.is_ascii_alphanumeric() || c.is_ascii_punctuation() || *c == 32)
 
&& idty_name
 
.0
 
.iter()
 
.zip(idty_name.0.iter().skip(1))
 
.all(|(c1, c2)| *c1 != 32 || *c2 != 32)
}
}
}
}
Loading