mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
fix: cover outer-scope bracket key handling
Agent-Logs-Url: https://github.com/microsoft/regorus/sessions/992f5462-7cc4-4e4f-bd7f-799308063765 Co-authored-by: anakrish <35780660+anakrish@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
5ae1d8abf2
commit
eb6e156e8a
@@ -181,6 +181,10 @@ impl<'a> Compiler<'a> {
|
||||
}
|
||||
|
||||
fn evaluate_default_rule(&mut self, rule_path: &str) -> Option<u16> {
|
||||
if !self.may_have_default_rule(rule_path) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut interpreter = Interpreter::new_from_compiled_policy(self.policy.inner.clone());
|
||||
|
||||
match interpreter.eval_default_rule_for_compiler(rule_path) {
|
||||
@@ -196,6 +200,33 @@ impl<'a> Compiler<'a> {
|
||||
None
|
||||
}
|
||||
|
||||
fn may_have_default_rule(&self, rule_path: &str) -> bool {
|
||||
if self.policy.inner.default_rules.contains_key(rule_path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let Some((parent_path, index)) = rule_path.rsplit_once('.') else {
|
||||
return false;
|
||||
};
|
||||
|
||||
self.policy
|
||||
.inner
|
||||
.default_rules
|
||||
.get(parent_path)
|
||||
.is_some_and(|rules| {
|
||||
rules
|
||||
.iter()
|
||||
.any(|(_, rule_index)| match rule_index.as_deref() {
|
||||
Some(rule_index) if rule_index == index => true,
|
||||
Some(rule_index) => rule_index
|
||||
.strip_prefix('"')
|
||||
.and_then(|rule_index| rule_index.strip_suffix('"'))
|
||||
.is_some_and(|rule_index| rule_index == index),
|
||||
None => false,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn extract_destructuring_blocks(&self, rule_index: u16) -> Vec<Option<u32>> {
|
||||
self.rule_definition_destructuring_patterns[rule_index as usize].clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user