Skip to content

Commit

Permalink
Feat/audit fix 0513 (#63)
Browse files Browse the repository at this point in the history
* Fix is_consecutive init value.

* Debugging

* fixes

* Debugging.

* Fix question tests.

* Modify tests and remove unused files.

* Fix caret bugs.

* Pass most tests

* Fix all bugs

* Add negate2 tests

* Fix: handle $

* fix

* chore: add errors

* Add dollar support

* Fix compile error.

* Add more dollar tests

* Remove unused test regex and circoms.

* Add regex limitations to README

---------

Co-authored-by: Aditya Bisht <adityabisht64@gmail.com>
  • Loading branch information
SoraSuegami and Bisht13 committed May 21, 2024
1 parent 9962a11 commit 5396ec4
Show file tree
Hide file tree
Showing 116 changed files with 9,481 additions and 2,025 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ packages/*/build
package-lock.json
yarn.lock

index.node
60 changes: 51 additions & 9 deletions packages/apis/src/extract_substrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@ pub fn extract_substr_idxes(
ExtractSubstrssError::SubstringOfEntireNotFound(entire_regex, input_str.to_string())
})?;
let mut start = entire_found.start();
let entire_end = entire_found.end();
// let entire_end: usize = entire_found.end();

let mut public_idxes = vec![];
for part_idx in 0..regex_config.parts.len() {
let regex = Regex::new(&regex_config.parts[part_idx].regex_def.as_str())?;
let found = regex.find_from_pos(&input_str, start)?.ok_or_else(|| {
ExtractSubstrssError::SubstringNotFound(
regex.clone(),
input_str[start..entire_end].to_string(),
)
})?;
let end = found.end();
let regex_def = regex_config.parts[part_idx].regex_def.as_str();
let regex = Regex::new(&regex_def)?;
let end = match regex.find_from_pos(&input_str, start)? {
Some(found) => found.end(),
None => start,
};
if regex_config.parts[part_idx].is_public {
public_idxes.push((start, end));
}
Expand Down Expand Up @@ -234,4 +232,48 @@ mod test {
let idxes = extract_message_id_idxes(input_str).unwrap();
assert_eq!(idxes, vec![(11, 79)]);
}


#[test]
fn test_dot_plus_valid() {
let code_regex = DecomposedRegexConfig {
parts: vec![
RegexPartConfig {
is_public: false,
regex_def: "a".to_string(),
},
RegexPartConfig {
is_public: true,
regex_def: ".+?".to_string(),
},
RegexPartConfig {
is_public: false,
regex_def: "b".to_string(),
},
],
};
let input_str = "azb";
let idxes = extract_substr_idxes(input_str, &code_regex).unwrap();
assert_eq!(idxes, vec![(1, 2)]);
}

#[test]
fn test_dot_question_valid() {
let code_regex = DecomposedRegexConfig {
parts: vec![
RegexPartConfig {
is_public: true,
regex_def: ".??".to_string(),
},
RegexPartConfig {
is_public: false,
regex_def: "b".to_string(),
},
],
};
let input_str = "b";
let idxes = extract_substr_idxes(input_str, &code_regex).unwrap();
assert_eq!(idxes, vec![(0, 0)]);
}

}
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/body_hash.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"parts": [
{
"is_public": false,
"regex_def": "((\r\n)|^)dkim-signature:"
"regex_def": "(\r\n|^)dkim-signature:"
},
{
"is_public": false,
Expand Down
Loading

0 comments on commit 5396ec4

Please sign in to comment.