From eec7158cdcf03efb3be9b3adc13a543f1b90bf77 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Tue, 27 Dec 2022 16:42:20 +0900 Subject: [PATCH 1/3] test(parser): Add test case to parse url with query param --- tests/utils/test_parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/utils/test_parser.py b/tests/utils/test_parser.py index 50179c7..d6eb5b3 100644 --- a/tests/utils/test_parser.py +++ b/tests/utils/test_parser.py @@ -13,6 +13,7 @@ def parser() -> Generator[Parser, None, None]: 'varst=variable to reStructuredText', 'version=0.2.0', 'release=v0.2.0', + 'url=https://example.com?query=new-value', ]) yield parser @@ -22,6 +23,7 @@ def test_parse_sub_pairs(parser: Parser): 'varst': 'variable to reStructuredText', 'version': '0.2.0', 'release': 'v0.2.0', + 'url': 'https://example.com?query=new-value', } From 8009371d74cf20f215254ee6577a584f8471f9ee Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Tue, 27 Dec 2022 16:42:45 +0900 Subject: [PATCH 2/3] feat(parser): Allow more than one equals sign --- varst/utils/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/varst/utils/parser.py b/varst/utils/parser.py index 7933d73..41249c0 100644 --- a/varst/utils/parser.py +++ b/varst/utils/parser.py @@ -70,7 +70,7 @@ def _pattern_type(arg_value: str, pat=_VARIABLE_PATTERN) -> str: argparse.ArgumentTypeError """ - if not pat.fullmatch(arg_value): + if not pat.match(arg_value): raise argparse.ArgumentTypeError(f"invalid pattern: {pat.pattern}") return arg_value @@ -107,7 +107,7 @@ def _parse_kv(variables: List[str]) -> Dict[str, str]: result: Dict[str, str] = {} for variable in variables: - kv = variable.split("=") + kv = variable.split("=", 1) result[kv.pop()] = kv.pop() return result From d5ff7fe59246c71a5165f6aef4ab15b878082d50 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Tue, 27 Dec 2022 16:43:45 +0900 Subject: [PATCH 3/3] test(parser): Remove unnessesary test case --- tests/utils/test_parser.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/utils/test_parser.py b/tests/utils/test_parser.py index d6eb5b3..604ac9a 100644 --- a/tests/utils/test_parser.py +++ b/tests/utils/test_parser.py @@ -48,17 +48,3 @@ def test_parse_one_element(parser: Parser): parser.parse(['key=']) with argparse_error(): parser.parse(['=value']) - - -def test_parse_more_than_two_element(parser: Parser): - with argparse_error(): - parser.parse(['key=value=else']) - - -def test_parse_many_equals(parser: Parser): - with argparse_error(): - parser.parse(['key==value']) - with argparse_error(): - parser.parse(['key===value']) - with argparse_error(): - parser.parse(['key====value'])