From e341af50c24db52607f99d166d7cfb41fe957e6f Mon Sep 17 00:00:00 2001 From: Fabrice Reix Date: Sat, 28 Sep 2024 20:17:09 +0200 Subject: [PATCH] Remove url-specific parser (align with grammar) --- .../hurl/tests_error_parser/invalid_url.err | 7 - .../hurl/tests_error_parser/invalid_url.exit | 1 - .../hurl/tests_error_parser/invalid_url.hurl | 1 - .../hurl/tests_error_parser/invalid_url.ps1 | 3 - .../hurl/tests_error_parser/invalid_url.sh | 3 - .../hurl/tests_error_parser/invalid_url_1.err | 7 - .../tests_error_parser/invalid_url_1.exit | 1 - .../tests_error_parser/invalid_url_1.hurl | 1 - .../hurl/tests_error_parser/invalid_url_1.ps1 | 3 - .../hurl/tests_error_parser/invalid_url_1.sh | 3 - .../hurl/tests_error_parser/invalid_url_2.err | 7 - .../tests_error_parser/invalid_url_2.exit | 1 - .../tests_error_parser/invalid_url_2.hurl | 1 - .../hurl/tests_error_parser/invalid_url_2.ps1 | 3 - .../hurl/tests_error_parser/invalid_url_2.sh | 3 - .../parallel_parsing_error.err | 8 +- .../parallel_parsing_error_c.hurl | 2 +- .../tests_error_parser/url_bad_prefix.err | 7 - .../tests_error_parser/url_bad_prefix.exit | 1 - .../tests_error_parser/url_bad_prefix.hurl | 4 - .../tests_error_parser/url_bad_prefix.ps1 | 3 - .../hurl/tests_error_parser/url_bad_prefix.sh | 3 - .../hurl/tests_ok/querystring_params.curl | 10 +- .../hurl/tests_ok/querystring_params.hurl | 7 +- .../hurl/tests_ok/querystring_params.py | 1 + integration/hurlfmt/tests_export/url.html | 5 +- integration/hurlfmt/tests_export/url.hurl | 3 +- integration/hurlfmt/tests_export/url.json | 2 +- .../hurlfmt/tests_export/url.lint.hurl | 3 +- packages/hurl_core/src/parser/mod.rs | 1 - packages/hurl_core/src/parser/parsers.rs | 8 +- packages/hurl_core/src/parser/url.rs | 333 ------------------ 32 files changed, 25 insertions(+), 421 deletions(-) delete mode 100644 integration/hurl/tests_error_parser/invalid_url.err delete mode 100644 integration/hurl/tests_error_parser/invalid_url.exit delete mode 100644 integration/hurl/tests_error_parser/invalid_url.hurl delete mode 100644 integration/hurl/tests_error_parser/invalid_url.ps1 delete mode 100755 integration/hurl/tests_error_parser/invalid_url.sh delete mode 100644 integration/hurl/tests_error_parser/invalid_url_1.err delete mode 100644 integration/hurl/tests_error_parser/invalid_url_1.exit delete mode 100644 integration/hurl/tests_error_parser/invalid_url_1.hurl delete mode 100644 integration/hurl/tests_error_parser/invalid_url_1.ps1 delete mode 100755 integration/hurl/tests_error_parser/invalid_url_1.sh delete mode 100644 integration/hurl/tests_error_parser/invalid_url_2.err delete mode 100644 integration/hurl/tests_error_parser/invalid_url_2.exit delete mode 100644 integration/hurl/tests_error_parser/invalid_url_2.hurl delete mode 100644 integration/hurl/tests_error_parser/invalid_url_2.ps1 delete mode 100755 integration/hurl/tests_error_parser/invalid_url_2.sh delete mode 100644 integration/hurl/tests_error_parser/url_bad_prefix.err delete mode 100644 integration/hurl/tests_error_parser/url_bad_prefix.exit delete mode 100644 integration/hurl/tests_error_parser/url_bad_prefix.hurl delete mode 100644 integration/hurl/tests_error_parser/url_bad_prefix.ps1 delete mode 100755 integration/hurl/tests_error_parser/url_bad_prefix.sh delete mode 100644 packages/hurl_core/src/parser/url.rs diff --git a/integration/hurl/tests_error_parser/invalid_url.err b/integration/hurl/tests_error_parser/invalid_url.err deleted file mode 100644 index 94699e96b98..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url.err +++ /dev/null @@ -1,7 +0,0 @@ -error: Parsing URL - --> tests_error_parser/invalid_url.hurl:1:26 - | - 1 | GET http://localhost:8000> # - | ^ illegal character <>> - | - diff --git a/integration/hurl/tests_error_parser/invalid_url.exit b/integration/hurl/tests_error_parser/invalid_url.exit deleted file mode 100644 index d8263ee9860..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url.exit +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/integration/hurl/tests_error_parser/invalid_url.hurl b/integration/hurl/tests_error_parser/invalid_url.hurl deleted file mode 100644 index 41872ef4490..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url.hurl +++ /dev/null @@ -1 +0,0 @@ -GET http://localhost:8000> # \ No newline at end of file diff --git a/integration/hurl/tests_error_parser/invalid_url.ps1 b/integration/hurl/tests_error_parser/invalid_url.ps1 deleted file mode 100644 index 4c3f7575f9f..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -Set-StrictMode -Version latest -$ErrorActionPreference = 'Stop' -hurl tests_error_parser/invalid_url.hurl diff --git a/integration/hurl/tests_error_parser/invalid_url.sh b/integration/hurl/tests_error_parser/invalid_url.sh deleted file mode 100755 index 72c6f28c084..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -Eeuo pipefail -hurl tests_error_parser/invalid_url.hurl diff --git a/integration/hurl/tests_error_parser/invalid_url_1.err b/integration/hurl/tests_error_parser/invalid_url_1.err deleted file mode 100644 index 99d6fdf35af..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_1.err +++ /dev/null @@ -1,7 +0,0 @@ -error: Parsing URL - --> tests_error_parser/invalid_url_1.hurl:1:5 - | - 1 | GET localhost:8000 - | ^ expecting http://, https:// or {{ - | - diff --git a/integration/hurl/tests_error_parser/invalid_url_1.exit b/integration/hurl/tests_error_parser/invalid_url_1.exit deleted file mode 100644 index d8263ee9860..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_1.exit +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/integration/hurl/tests_error_parser/invalid_url_1.hurl b/integration/hurl/tests_error_parser/invalid_url_1.hurl deleted file mode 100644 index 2626e08ee94..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_1.hurl +++ /dev/null @@ -1 +0,0 @@ -GET localhost:8000 diff --git a/integration/hurl/tests_error_parser/invalid_url_1.ps1 b/integration/hurl/tests_error_parser/invalid_url_1.ps1 deleted file mode 100644 index 68c73ccbe77..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_1.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -Set-StrictMode -Version latest -$ErrorActionPreference = 'Stop' -hurl tests_error_parser/invalid_url_1.hurl diff --git a/integration/hurl/tests_error_parser/invalid_url_1.sh b/integration/hurl/tests_error_parser/invalid_url_1.sh deleted file mode 100755 index 9165bf4ac0d..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_1.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -Eeuo pipefail -hurl tests_error_parser/invalid_url_1.hurl diff --git a/integration/hurl/tests_error_parser/invalid_url_2.err b/integration/hurl/tests_error_parser/invalid_url_2.err deleted file mode 100644 index bfae406bd10..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_2.err +++ /dev/null @@ -1,7 +0,0 @@ -error: Parsing URL - --> tests_error_parser/invalid_url_2.hurl:1:5 - | - 1 | GET http:localhost:8000 - | ^ expecting http://, https:// or {{ - | - diff --git a/integration/hurl/tests_error_parser/invalid_url_2.exit b/integration/hurl/tests_error_parser/invalid_url_2.exit deleted file mode 100644 index d8263ee9860..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_2.exit +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/integration/hurl/tests_error_parser/invalid_url_2.hurl b/integration/hurl/tests_error_parser/invalid_url_2.hurl deleted file mode 100644 index 0fa8679f2b4..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_2.hurl +++ /dev/null @@ -1 +0,0 @@ -GET http:localhost:8000 diff --git a/integration/hurl/tests_error_parser/invalid_url_2.ps1 b/integration/hurl/tests_error_parser/invalid_url_2.ps1 deleted file mode 100644 index c0a0f25ca27..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_2.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -Set-StrictMode -Version latest -$ErrorActionPreference = 'Stop' -hurl tests_error_parser/invalid_url_2.hurl diff --git a/integration/hurl/tests_error_parser/invalid_url_2.sh b/integration/hurl/tests_error_parser/invalid_url_2.sh deleted file mode 100755 index 957c302a712..00000000000 --- a/integration/hurl/tests_error_parser/invalid_url_2.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -Eeuo pipefail -hurl tests_error_parser/invalid_url_2.hurl diff --git a/integration/hurl/tests_error_parser/parallel_parsing_error.err b/integration/hurl/tests_error_parser/parallel_parsing_error.err index 3392439212e..5a67a13bb31 100644 --- a/integration/hurl/tests_error_parser/parallel_parsing_error.err +++ b/integration/hurl/tests_error_parser/parallel_parsing_error.err @@ -1,7 +1,7 @@ -error: Parsing URL - --> tests_error_parser/parallel_parsing_error_c.hurl:4:5 +error: Parsing space + --> tests_error_parser/parallel_parsing_error_c.hurl:4:4  | - 4 | GET //localhost:8000/hello - | ^ expecting http://, https:// or {{ + 4 | GET//localhost:8000/hello + | ^ expecting a space  | diff --git a/integration/hurl/tests_error_parser/parallel_parsing_error_c.hurl b/integration/hurl/tests_error_parser/parallel_parsing_error_c.hurl index 619b1aec6fc..523d98156ad 100644 --- a/integration/hurl/tests_error_parser/parallel_parsing_error_c.hurl +++ b/integration/hurl/tests_error_parser/parallel_parsing_error_c.hurl @@ -1,7 +1,7 @@ GET http://localhost:8000/hello HTTP 200 -GET //localhost:8000/hello +GET//localhost:8000/hello HTTP 200 GET http://localhost:8000/hello diff --git a/integration/hurl/tests_error_parser/url_bad_prefix.err b/integration/hurl/tests_error_parser/url_bad_prefix.err deleted file mode 100644 index a05d3ccad5c..00000000000 --- a/integration/hurl/tests_error_parser/url_bad_prefix.err +++ /dev/null @@ -1,7 +0,0 @@ -error: Parsing URL - --> tests_error_parser/url_bad_prefix.hurl:4:5 - | - 4 | GET "http://localhost:8000" - | ^ expecting http://, https:// or {{ - | - diff --git a/integration/hurl/tests_error_parser/url_bad_prefix.exit b/integration/hurl/tests_error_parser/url_bad_prefix.exit deleted file mode 100644 index d8263ee9860..00000000000 --- a/integration/hurl/tests_error_parser/url_bad_prefix.exit +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git a/integration/hurl/tests_error_parser/url_bad_prefix.hurl b/integration/hurl/tests_error_parser/url_bad_prefix.hurl deleted file mode 100644 index fd27717fe5a..00000000000 --- a/integration/hurl/tests_error_parser/url_bad_prefix.hurl +++ /dev/null @@ -1,4 +0,0 @@ -# URL in Hurl are not quoted strings: -# it's should be: -# GET http://localhost:8000 -GET "http://localhost:8000" \ No newline at end of file diff --git a/integration/hurl/tests_error_parser/url_bad_prefix.ps1 b/integration/hurl/tests_error_parser/url_bad_prefix.ps1 deleted file mode 100644 index f45351ae997..00000000000 --- a/integration/hurl/tests_error_parser/url_bad_prefix.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -Set-StrictMode -Version latest -$ErrorActionPreference = 'Stop' -hurl tests_error_parser/url_bad_prefix.hurl diff --git a/integration/hurl/tests_error_parser/url_bad_prefix.sh b/integration/hurl/tests_error_parser/url_bad_prefix.sh deleted file mode 100755 index 2b3dc0672c3..00000000000 --- a/integration/hurl/tests_error_parser/url_bad_prefix.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -Eeuo pipefail -hurl tests_error_parser/url_bad_prefix.hurl diff --git a/integration/hurl/tests_ok/querystring_params.curl b/integration/hurl/tests_ok/querystring_params.curl index 159caf197a8..1b1e05be059 100644 --- a/integration/hurl/tests_ok/querystring_params.curl +++ b/integration/hurl/tests_ok/querystring_params.curl @@ -1,7 +1,7 @@ -curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3&$top=5' -curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3&$top=5' -curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3&$top=5' -curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3&$top=5' -curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3&$top=5' +curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3¶m5=\{bar\}&$top=5' +curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3¶m5=\{bar\}&$top=5' +curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3¶m5=\{bar\}&$top=5' +curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3¶m5=\{bar\}&$top=5' +curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3¶m5=\{bar\}&$top=5' curl 'http://localhost:8000/querystring-params-encoded?value1=/&value2=%2F&value3=%2F' curl 'http://localhost:8000/querystring-params-encoded?value1=/&value2=%2F&value3=%2F' diff --git a/integration/hurl/tests_ok/querystring_params.hurl b/integration/hurl/tests_ok/querystring_params.hurl index 1f205471de7..991c69e7cd9 100644 --- a/integration/hurl/tests_ok/querystring_params.hurl +++ b/integration/hurl/tests_ok/querystring_params.hurl @@ -4,6 +4,7 @@ param1: value1 param2: param3: a=b param4: 1,2,3 +param5: {bar} $top: 5 HTTP 200 @@ -14,12 +15,13 @@ param1: value1 param2: param3: a=b param4: 1,2,3 +param5: {bar} $top: 5 HTTP 200 # Same version as raw -GET http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3&$top=5 +GET http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3¶m5={bar}&$top=5 HTTP 200 @@ -29,11 +31,12 @@ GET http://localhost:8000/querystring-params?param1=value1 param2: param3: a=b param4: 1,2,3 +param5: {bar} $top: 5 HTTP 200 -GET http://localhost:8000/querystring-params?param1=value1 +GET http://localhost:8000/querystring-params?param1=value1¶m5={bar} [Query] param2: param3: a=b diff --git a/integration/hurl/tests_ok/querystring_params.py b/integration/hurl/tests_ok/querystring_params.py index 9ad1f3b71c4..90cbac8cffd 100644 --- a/integration/hurl/tests_ok/querystring_params.py +++ b/integration/hurl/tests_ok/querystring_params.py @@ -8,6 +8,7 @@ def querystring_params(): assert request.args.get("param2") == "" assert request.args.get("param3") == "a=b" assert request.args.get("param4") == "1,2,3" + assert request.args.get("param5") == "{bar}" assert request.args.get("$top") == "5" return "" diff --git a/integration/hurlfmt/tests_export/url.html b/integration/hurlfmt/tests_export/url.html index cdb2331fb26..419de2ea377 100644 --- a/integration/hurlfmt/tests_export/url.html +++ b/integration/hurlfmt/tests_export/url.html @@ -1,6 +1,5 @@
GET http://localhost:8000/~user
 GET http://localhost:8000/%7Euser
 GET http://localhost:8000/!$&()*+,;=:@[]
-
-
-
+GET http://localhost:8000?foo={bar} + diff --git a/integration/hurlfmt/tests_export/url.hurl b/integration/hurlfmt/tests_export/url.hurl index 7e4b2cdcb3e..5178930866a 100644 --- a/integration/hurlfmt/tests_export/url.hurl +++ b/integration/hurlfmt/tests_export/url.hurl @@ -1,5 +1,4 @@ GET http://localhost:8000/~user GET http://localhost:8000/%7Euser GET http://localhost:8000/!$&()*+,;=:@[] - - +GET http://localhost:8000?foo={bar} diff --git a/integration/hurlfmt/tests_export/url.json b/integration/hurlfmt/tests_export/url.json index 241856726c0..86b8c02e02c 100644 --- a/integration/hurlfmt/tests_export/url.json +++ b/integration/hurlfmt/tests_export/url.json @@ -1 +1 @@ -{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/~user"}},{"request":{"method":"GET","url":"http://localhost:8000/%7Euser"}},{"request":{"method":"GET","url":"http://localhost:8000/!$&()*+,;=:@[]"}}]} +{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/~user"}},{"request":{"method":"GET","url":"http://localhost:8000/%7Euser"}},{"request":{"method":"GET","url":"http://localhost:8000/!$&()*+,;=:@[]"}},{"request":{"method":"GET","url":"http://localhost:8000?foo={bar}"}}]} diff --git a/integration/hurlfmt/tests_export/url.lint.hurl b/integration/hurlfmt/tests_export/url.lint.hurl index 7e4b2cdcb3e..5178930866a 100644 --- a/integration/hurlfmt/tests_export/url.lint.hurl +++ b/integration/hurlfmt/tests_export/url.lint.hurl @@ -1,5 +1,4 @@ GET http://localhost:8000/~user GET http://localhost:8000/%7Euser GET http://localhost:8000/!$&()*+,;=:@[] - - +GET http://localhost:8000?foo={bar} diff --git a/packages/hurl_core/src/parser/mod.rs b/packages/hurl_core/src/parser/mod.rs index 9e0078a217b..2fd4f38a361 100644 --- a/packages/hurl_core/src/parser/mod.rs +++ b/packages/hurl_core/src/parser/mod.rs @@ -53,5 +53,4 @@ mod query; mod sections; mod string; mod template; -mod url; mod xml; diff --git a/packages/hurl_core/src/parser/parsers.rs b/packages/hurl_core/src/parser/parsers.rs index 8272e7402a9..002f96da4d5 100644 --- a/packages/hurl_core/src/parser/parsers.rs +++ b/packages/hurl_core/src/parser/parsers.rs @@ -23,10 +23,11 @@ use crate::parser::error::*; use crate::parser::number::natural; use crate::parser::primitives::*; use crate::parser::sections::*; -use crate::parser::url::url; use crate::parser::ParseResult; use crate::reader::Reader; +use super::string::unquoted_template; + pub fn hurl_file(reader: &mut Reader) -> ParseResult { let entries = zero_or_more(entry, reader)?; let line_terminators = optional_line_terminators(reader)?; @@ -52,8 +53,7 @@ fn request(reader: &mut Reader) -> ParseResult { let space0 = zero_or_more_spaces(reader)?; let m = method(reader)?; let space1 = one_or_more_spaces(reader)?; - let u = url(reader)?; - + let url = unquoted_template(reader)?; let line_terminator0 = line_terminator(reader)?; let headers = zero_or_more(key_value, reader)?; let sections = request_sections(reader)?; @@ -79,7 +79,7 @@ fn request(reader: &mut Reader) -> ParseResult { space0, method: m, space1, - url: u, + url, line_terminator0, headers, sections, diff --git a/packages/hurl_core/src/parser/url.rs b/packages/hurl_core/src/parser/url.rs deleted file mode 100644 index 9866c2635be..00000000000 --- a/packages/hurl_core/src/parser/url.rs +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Hurl (https://hurl.dev) - * Copyright (C) 2024 Orange - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -use crate::ast::*; -use crate::parser::error::*; -use crate::parser::primitives::*; -use crate::parser::{expr, ParseResult}; -use crate::reader::Reader; - -pub fn url(reader: &mut Reader) -> ParseResult