Fix escaping of integer indexes with multiple backslashes (#1288)

This commit is contained in:
Batuhan Taskaya 2022-02-01 13:10:55 +03:00 committed by GitHub
parent 7abddfe350
commit f1ea486025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 12 deletions

View File

@ -3,6 +3,10 @@
This document records all notable changes to [HTTPie](https://httpie.io).
This project adheres to [Semantic Versioning](https://semver.org/).
## Unreleased
- Fixed escaping of integer indexes with multiple backslashes in the nested JSON builder. ([#1285](https://github.com/httpie/httpie/issues/1285))
## [3.0.2](https://github.com/httpie/httpie/compare/3.0.1...3.0.2) (2022-01-24)
[Whats new in HTTPie for Terminal 3.0 →](https://httpie.io/blog/httpie-3.0.0)

View File

@ -88,18 +88,18 @@ def tokenize(source: str) -> Iterator[Token]:
return None
value = ''.join(buffer)
for variation, kind in [
(int, TokenKind.NUMBER),
(check_escaped_int, TokenKind.TEXT),
]:
try:
value = variation(value)
except ValueError:
continue
else:
break
else:
kind = TokenKind.TEXT
kind = TokenKind.TEXT
if not backslashes:
for variation, kind in [
(int, TokenKind.NUMBER),
(check_escaped_int, TokenKind.TEXT),
]:
try:
value = variation(value)
except ValueError:
continue
else:
break
yield Token(
kind, value, start=cursor - (len(buffer) + backslashes), end=cursor

View File

@ -397,6 +397,28 @@ def test_complex_json_arguments_with_non_json(httpbin, request_type, value):
'2012': {'x': 2, '[3]': 4},
},
),
(
[
r'a[\0]:=0',
r'a[\\1]:=1',
r'a[\\\2]:=2',
r'a[\\\\\3]:=3',
r'a[-1\\]:=-1',
r'a[-2\\\\]:=-2',
r'a[\\-3\\\\]:=-3',
],
{
"a": {
"0": 0,
r"\1": 1,
r"\\2": 2,
r"\\\3": 3,
"-1\\": -1,
"-2\\\\": -2,
"\\-3\\\\": -3,
}
}
),
],
)
def test_nested_json_syntax(input_json, expected_json, httpbin):