Skip to content

Commit ef082ab

Browse files
committed
fix: if body contains a url which has '-', the grammar will break
1 parent bea3ee3 commit ef082ab

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "curl-parser"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
edition = "2021"
55
license = "MIT"
66
documentation = "https://docs.rs/curl-parser"

src/curl.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ location_option = _{ ("-L" | "--location") ~ ws+ ~ location }
2525
location = { single_quoted | double_quoted | none_ws }
2626

2727
body_option = _{ ("-d" | "--data") ~ ws+ ~ body }
28-
body = { (!(("-" ~ ASCII_ALPHA_UPPER) | ("--" ~ ASCII_ALPHA_LOWER) | "\\") ~ ANY)+ }
28+
body = { (!((" -" ~ ASCII_ALPHA_UPPER) | (" --" ~ ASCII_ALPHA_LOWER) | "\\") ~ ANY)+ }
2929

3030
auth_option = _{ "-u" ~ ws+ ~ auth }
3131
auth = { single_quoted | double_quoted | none_ws }

src/parser.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,13 @@ mod tests {
302302
assert!(parsed.insecure);
303303
Ok(())
304304
}
305+
306+
#[tokio::test]
307+
async fn parse_curl_with_body_should_work() -> Result<()> {
308+
let input = r#"curl --location https://example.com --header 'Content-Type: application/json' -d '{"name":"John","age":30}'"#;
309+
let parsed = ParsedRequest::from_str(input)?;
310+
assert_eq!(parsed.method, Method::POST);
311+
assert_eq!(parsed.body, vec!["{\"name\":\"John\",\"age\":30}"]);
312+
Ok(())
313+
}
305314
}

0 commit comments

Comments
 (0)