Skip to content

Commit

Permalink
Improve heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh1Yo committed Jul 7, 2021
1 parent f584819 commit e144d47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "x8"
version = "2.2.1"
version = "2.3.0"
authors = ["Alexander Mironov <[email protected]>"]
edition = "2018"
license = "GPL-3.0-or-later"
Expand Down
12 changes: 9 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ pub fn compare(
(code, diffs)
}

//get possible parameters from the page source code
//get possible parameters from the page code
pub fn heuristic(body: &str) -> Vec<String> {
let mut found: Vec<String> = Vec::new();

let re_special_chars = Regex::new(r#"[\W]"#).unwrap();

let re_name = Regex::new(r#"(?i)name=("|')?"#).unwrap();
let re_inputs = Regex::new(r#"(?i)name=("|')?[\w-]+"#).unwrap();
for cap in re_inputs.captures_iter(body) {
Expand All @@ -84,10 +86,14 @@ pub fn heuristic(body: &str) -> Vec<String> {
found.push(re_var.replace_all(&cap[0], "").to_string());
}

let re_quotes = Regex::new(r#"("|')"#).unwrap();
let re_words_in_quotes = Regex::new(r#"("|')\w{3,20}('|")"#).unwrap();
for cap in re_words_in_quotes.captures_iter(body) {
found.push(re_quotes.replace_all(&cap[0], "").to_string());
found.push(re_special_chars.replace_all(&cap[0], "").to_string());
}

let re_words_within_objects = Regex::new(r#"[\{,]\s*[[:alpha:]]\w{2,25}:"#).unwrap();
for cap in re_words_within_objects.captures_iter(body){
found.push(re_special_chars.replace_all(&cap[0], "").to_string());
}

found.sort();
Expand Down

0 comments on commit e144d47

Please sign in to comment.