From 3a7574bb4bb4776ff1eb31d0abc3dd9ef725c230 Mon Sep 17 00:00:00 2001 From: Brian Payne Date: Thu, 16 Jan 2020 08:03:19 -0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Newlines=20in=20request=20bo?= =?UTF-8?q?dy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GH-6 --- Cargo.toml | 4 ---- src/parser/parser.pest | 6 ++--- src/parser/tests.rs | 52 +++++++++++++++++++++++++++++++----------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 703292e..cffc9cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,3 @@ serde = { version = "1.0", features = ["derive"] } [dev-dependencies] http-test-server = "1.0.0" tempfile = "3.1.0" - -#[dependencies.futures-preview] -#version = "0.3.0-alpha.18" -#features = ["compat", "io-compat"] diff --git a/src/parser/parser.pest b/src/parser/parser.pest index 53ff8c4..b442f2c 100644 --- a/src/parser/parser.pest +++ b/src/parser/parser.pest @@ -18,8 +18,8 @@ inline_script_string = { inline_script_string_character* } inline_script_string_character = _{ !inline_script_end ~ !"{{" ~ ANY} inline_script_end = _{ SP* ~ "}}" } -request_script = { request ~ (CRLF ~ request_body)? ~ (CRLF{2,} ~ request_handler)? ~ CRLF* ~ request_separator* } -request_body = ${ (!request_separator ~ !CRLF{2,} ~ (inline_script | ANY))+ } +request_script = { request ~ (CRLF ~ request_body)? ~ (CRLF{2,} ~ request_handler)? } +request_body = ${ (!(CRLF* ~ request_separator) ~ !(CRLF* ~ handler_script_start) ~ !(CRLF* ~ EOI) ~ (inline_script | ANY))+ } request_handler = ${ !request_separator ~ handler_script } request = _{ request_line ~ CRLF ~ (header_field ~ CRLF)* } @@ -33,4 +33,4 @@ header_field = ${ field_name ~ ":" ~ SP* ~ field_value} field_name = { token } field_value = { (!CRLF ~ (inline_script | ANY))* } -file = { SOI ~ CRLF* ~ (request_script ~ CRLF*)* ~ EOI } +file = { SOI ~ CRLF* ~ (request_script ~ CRLF* ~ ((request_separator ~ CRLF*) | EOI))* ~ EOI } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 605f567..2793033 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -58,9 +58,7 @@ Content-Type: {{ content_type }} > {% console.log('Success!'); -%} - -###" +%}" ); let mut request_script_parts = request_script.into_inner(); @@ -88,8 +86,7 @@ Content-Type: {{ content_type }} "\ GET http://example.com/{{url_param}} Accept: */* - -###" +" ); let mut request_script_parts = request_script.into_inner(); @@ -112,6 +109,35 @@ fn test_min_file() { assert!(file.is_ok()); } +#[test] +fn test_new_line_in_request_body_file() { + let test = "\ +POST http://example.com HTTP/1.1 +Accept: */* + +{ + \"test\": \"a\", + \"what\": [ + + ] +} + + +> {% + console.log('cool'); +%} + +### +"; + + let file = ScriptParser::parse(Rule::file, test); + if let Err(e) = &file { + println!("{:?}", e); + } + + assert!(file.is_ok()); +} + #[test] fn test_request_script() { let test = "\ @@ -309,7 +335,7 @@ Accept: */* selection: Selection { filename: Path::new("").to_path_buf(), start: Position { line: 4, col: 1 }, - end: Position { line: 19, col: 4 }, + end: Position { line: 17, col: 3 }, }, }, handler: Some(Handler { @@ -323,7 +349,7 @@ Accept: */* selection: Selection { filename: Path::new("").to_path_buf(), start: Position { line: 4, col: 1 }, - end: Position { line: 19, col: 4 }, + end: Position { line: 17, col: 3 }, }, }, RequestScript { @@ -374,14 +400,14 @@ Accept: */* selection: Selection { filename: Path::new("").to_path_buf(), start: Position { line: 22, col: 1 }, - end: Position { line: 25, col: 1 }, + end: Position { line: 24, col: 1 }, }, }, handler: None, selection: Selection { filename: Path::new("").to_path_buf(), start: Position { line: 22, col: 1 }, - end: Position { line: 25, col: 1 }, + end: Position { line: 24, col: 1 }, }, }, ], @@ -435,7 +461,7 @@ Accept: */* selection: Selection { filename: Path::new("").to_path_buf(), start: Position { line: 4, col: 1 }, - end: Position { line: 19, col: 4 }, + end: Position { line: 17, col: 3 }, }, }, handler: Some(Handler { @@ -449,7 +475,7 @@ Accept: */* selection: Selection { filename: Path::new("").to_path_buf(), start: Position { line: 4, col: 1 }, - end: Position { line: 19, col: 4 }, + end: Position { line: 17, col: 3 }, }, }, RequestScript { @@ -481,14 +507,14 @@ Accept: */* selection: Selection { filename: Path::new("").to_path_buf(), start: Position { line: 22, col: 1 }, - end: Position { line: 25, col: 1 }, + end: Position { line: 24, col: 1 }, }, }, handler: None, selection: Selection { filename: Path::new("").to_path_buf(), start: Position { line: 22, col: 1 }, - end: Position { line: 25, col: 1 }, + end: Position { line: 24, col: 1 }, }, }, ], From c626d20aae8b36e437a479e83f0e52c33742fac8 Mon Sep 17 00:00:00 2001 From: Brian Payne Date: Thu, 16 Jan 2020 13:31:10 -0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Empty=20body=20with=20respon?= =?UTF-8?q?se=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GH-6 --- src/parser/parser.pest | 2 +- src/parser/tests.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/parser/parser.pest b/src/parser/parser.pest index b442f2c..b7d9de9 100644 --- a/src/parser/parser.pest +++ b/src/parser/parser.pest @@ -18,7 +18,7 @@ inline_script_string = { inline_script_string_character* } inline_script_string_character = _{ !inline_script_end ~ !"{{" ~ ANY} inline_script_end = _{ SP* ~ "}}" } -request_script = { request ~ (CRLF ~ request_body)? ~ (CRLF{2,} ~ request_handler)? } +request_script = { request ~ (CRLF ~ request_body)? ~ (CRLF+ ~ request_handler)? } request_body = ${ (!(CRLF* ~ request_separator) ~ !(CRLF* ~ handler_script_start) ~ !(CRLF* ~ EOI) ~ (inline_script | ANY))+ } request_handler = ${ !request_separator ~ handler_script } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 2793033..32020bd 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -109,6 +109,26 @@ fn test_min_file() { assert!(file.is_ok()); } +#[test] +fn test_empty_body_with_handler() { + let test = "\ +POST http://example.com HTTP/1.1 +Accept: */* + +> {% + console.log('cool'); +%} +### +"; + + let file = ScriptParser::parse(Rule::file, test); + if let Err(e) = &file { + println!("{:?}", e); + } + + assert!(file.is_ok()); +} + #[test] fn test_new_line_in_request_body_file() { let test = "\