From 34c224acee8edcca655f08623430ec96c37c182d Mon Sep 17 00:00:00 2001 From: Fadel333 Date: Mon, 28 Sep 2026 12:59:12 +0000 Subject: [PATCH 1/2] Add failing test for quoting hint in unquoted multi-word value error --- tests/test_cli.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 2cd27574af..89f4e3725b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -27,6 +27,47 @@ def test_invalid_items(self): for item in items: pytest.raises(argparse.ArgumentTypeError, self.key_value_arg, item) + def test_quoted_multiword_value_parses_correctly(self): + """A properly quoted multi-word value parses correctly. + + When the shell passes `field_name=Foo Bar` as a single argument + (i.e. the user quoted it), HTTPie should accept it and keep the + full string as the value. + """ + item = self.key_value_arg('field_name=Foo Bar') + assert item.key == 'field_name' + assert item.value == 'Foo Bar' + + def test_unquoted_multiword_value_second_token_raises(self): + """A bare fragment like 'Bar' raises ArgumentTypeError. + + When a user forgets to quote a multi-word value, the shell splits + `field_name=Foo Bar` into two arguments: `field_name=Foo` and + `Bar`. The second one has no separator and must be rejected. + """ + with pytest.raises(argparse.ArgumentTypeError): + self.key_value_arg('Bar') + + def test_unquoted_multiword_value_error_contains_quoting_hint(self): + """The error for an unquoted fragment should hint about quoting. + + The current message ('Bar' is not a valid value) is technically + correct but does not tell the user that the real problem is a + missing pair of quotes around a multi-word value. + """ + with pytest.raises(argparse.ArgumentTypeError) as exc_info: + self.key_value_arg('Bar') + message = str(exc_info.value) + assert 'quote' in message.lower(), ( + f"Expected a quoting hint in the error message, got: {message!r}" + ) + assert ( + 'multi-word' in message.lower() + or 'multiple words' in message.lower() + ), ( + f"Expected the hint to mention multi-word values, got: {message!r}" + ) + def test_escape_separator(self): items = RequestItems.from_args([ # headers From b7732e8011f88a698df34e1b4d342d58a6eed023 Mon Sep 17 00:00:00 2001 From: Fadel333 Date: Mon, 28 Sep 2026 13:03:36 +0000 Subject: [PATCH 2/2] Add quoting hint to invalid REQUEST_ITEM error message --- httpie/cli/argtypes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/httpie/cli/argtypes.py b/httpie/cli/argtypes.py index 8f19c3c51e..9ddefcadea 100644 --- a/httpie/cli/argtypes.py +++ b/httpie/cli/argtypes.py @@ -103,8 +103,11 @@ def __call__(self, s: str) -> KeyValueArg: break else: - raise argparse.ArgumentTypeError(f'{s!r} is not a valid value') - + raise argparse.ArgumentTypeError( + f'{s!r} is not a valid value. ' + f'Did you forget to quote a multi-word value? ' + f'Try wrapping it in quotes, e.g. field_name="Foo Bar"' + ) return self.key_value_class(key=key, value=value, sep=sep, orig=s) def tokenize(self, s: str) -> List[Union[str, Escaped]]: