Skip to content

Commit edb35cb

Browse files
author
Cheng JIANG
committed
move _ count check outside of loop
1 parent f43bb84 commit edb35cb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/model/assertion.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ impl Assertion {
4747

4848
pub fn build_role_links(&mut self, rm: Arc<RwLock<dyn RoleManager>>) -> Result<()> {
4949
let count = self.value.chars().filter(|&c| c == '_').count();
50+
if count < 2 {
51+
return Err(ModelError::P(
52+
r#"the number of "_" in role definition should be at least 2"#.to_owned(),
53+
)
54+
.into());
55+
}
5056
for rule in &self.policy {
51-
if count < 2 {
52-
return Err(ModelError::P(
53-
r#"the number of "_" in role definition should be at least 2"#.to_owned(),
54-
)
55-
.into());
56-
}
5757
if rule.len() < count {
5858
return Err(PolicyError::UnmatchPolicyDefinition(count, rule.len()).into());
5959
}
@@ -78,6 +78,12 @@ impl Assertion {
7878
d: EventData,
7979
) -> Result<()> {
8080
let count = self.value.chars().filter(|&c| c == '_').count();
81+
if count < 2 {
82+
return Err(ModelError::P(
83+
r#"the number of "_" in role definition should be at least 2"#.to_owned(),
84+
)
85+
.into());
86+
}
8187

8288
if let Some((insert, rules)) = match d {
8389
EventData::AddPolicy(_, _, rule) => Some((true, vec![rule])),
@@ -88,12 +94,6 @@ impl Assertion {
8894
_ => None,
8995
} {
9096
for rule in rules {
91-
if count < 2 {
92-
return Err(ModelError::P(
93-
r#"the number of "_" in role definition should be at least 2"#.to_owned(),
94-
)
95-
.into());
96-
}
9797
if rule.len() < count {
9898
return Err(PolicyError::UnmatchPolicyDefinition(count, rule.len()).into());
9999
}

0 commit comments

Comments
 (0)