Skip to content

Commit

Permalink
Add support for writing multiline queries
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealLorenz committed Dec 2, 2023
1 parent 40a81e8 commit 39255e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion demo.http
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ GET https://httpbin.org/get?param1=2&param2=3

###

GET https://httpbin.org/get?param1=" 2"&param2=" 3"
GET https://httpbin.org/get
?param1=" 2"
&param2=" 3"

2 changes: 1 addition & 1 deletion rq-core/src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ method = { ("GET" | "DELETE" | "POST" | "PUT") }
version = { "HTTP/" ~ ("0.9" | "1.0" | "1.1" | "2.0" | "3.0") }
whitespace = _{ " " | "\t" | NEWLINE }

query = { "?" ~ query_item ~ ("&" ~ query_item)* }
query = { (NEWLINE ~ (" " | "\t")*)? ~ "?" ~ query_item ~ ((NEWLINE ~ (" " | "\t")*)? ~ "&" ~ query_item)* }
query_item = { query_name ~ "=" ~ query_value }
query_name = { (!(NEWLINE | "=") ~ ANY)+ }
query_value = { (PUSH("'" | "\"") ~ (!PEEK ~ ANY)* ~ POP) | (!(NEWLINE | "&" | " ") ~ ANY)+ }
Expand Down
16 changes: 16 additions & 0 deletions rq-core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,20 @@ authorization: token
assert_eq!(file.requests[0].query.get("foo").unwrap(), " bar");
assert_eq!(file.requests[0].query.get("baz").unwrap(), " &ciao");
}

#[test]
fn test_multiline_query() {
let input = r#"
POST test.dev
?foo=bar
&baz=42 HTTP/1.0
authorization: token
"#;
let file = assert_parses(input);
assert_eq!(file.requests.len(), 1);
assert_eq!(file.requests[0].query.len(), 2);
assert_eq!(file.requests[0].query.get("foo").unwrap(), "bar");
assert_eq!(file.requests[0].query.get("baz").unwrap(), "42");
}
}

0 comments on commit 39255e7

Please sign in to comment.