Skip to content

Commit

Permalink
Bug fix #34
Browse files Browse the repository at this point in the history
  • Loading branch information
SummerGram committed Mar 3, 2024
1 parent 365a485 commit e522377
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/utils/regexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod request_items {

static BODY_VALUE_REGEX: OnceLock<Regex> = OnceLock::new();
pub fn body_value() -> &'static Regex {
BODY_VALUE_REGEX.get_or_init(|| Regex::new(r"^(?<key>[ -~]+)=(?<value>[ -~]+)$").unwrap())
BODY_VALUE_REGEX.get_or_init(|| Regex::new(r"^(?<key>[ -~]*[^:=])=(?<value>[ -~]+)$").unwrap())
}

static NESTED_BODY_KEYS_REGEX: OnceLock<Regex> = OnceLock::new();
Expand Down
25 changes: 21 additions & 4 deletions src/view/input_parsers/request_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ pub mod tests_parsers_request_items {
),
];

for (input, output) in cases {
for (input, expected_json_output) in cases {
let base_request = PartialRequestData::default();

let expected_result = PartialRequestData::default().with_body(output.to_string());
let expected_result = PartialRequestData::default().with_body(expected_json_output);

assert_eq!(
parsers_request_items::non_string_body_value(input, &base_request),
Expand Down Expand Up @@ -355,10 +355,10 @@ pub mod tests_parsers_request_items {
(r#"worked:='null'"#, r#"{ "worked": null }"#),
];

for (input, output) in cases {
for (input, expected_json_output) in cases {
let base_request = PartialRequestData::default();

let expected_result = PartialRequestData::default().with_body(output.to_string());
let expected_result = PartialRequestData::default().with_body(expected_json_output);

assert_eq!(
parsers_request_items::non_string_body_value(input, &base_request),
Expand Down Expand Up @@ -415,6 +415,23 @@ pub mod tests_parsers_request_items {
}
}

#[test]
fn test_invalid_body_value() {
let cases = [
r#"key:={"name":]"#,
r#"key:=name"#,
];

for input in cases {
let base_request = PartialRequestData::default();

assert_eq!(
None,
parsers_request_items::body_value(input, &base_request)
)
}
}

#[test]
fn test_body_value_with_base_body_none() {
let input = "password=123";
Expand Down

0 comments on commit e522377

Please sign in to comment.