Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nested json syntax #217

Merged
merged 24 commits into from
Jun 9, 2022
Merged

Add support for nested json syntax #217

merged 24 commits into from
Jun 9, 2022

Conversation

ducaale
Copy link
Owner

@ducaale ducaale commented Dec 29, 2021

Resolves #3

@ducaale ducaale force-pushed the nested-json branch 7 times, most recently from 5d0b8c1 to 7f7023d Compare December 31, 2021 16:17
@ducaale ducaale marked this pull request as ready for review December 31, 2021 16:47
@ducaale ducaale marked this pull request as draft January 6, 2022 23:17
@ducaale ducaale force-pushed the nested-json branch 2 times, most recently from a290382 to 2e3d656 Compare January 29, 2022 19:51
- Numbers can be escaped in order to be treated as string
  e.g foo[\5]=hello.
- Data type clashes will lead to a hard error e.g foo[x]=5 foo[]=6
  or x=5 x[x]=7.
- The "append by default" behavior has been abandoned e.g x=1 x=2 equals
  {"x": "1"} instead of {"x": ["1", "2"]}.
@ducaale ducaale marked this pull request as ready for review March 1, 2022 21:29
@blyxxyz blyxxyz self-requested a review April 16, 2022 18:12
Copy link
Collaborator

@blyxxyz blyxxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long to review this!

It works well, everything I threw at it matches HTTPie (with one small exception that maybe doesn't need to be fixed).

Some of the error messages could be better, but we can just merge it and make an issue for that.

src/nested_json.rs Show resolved Hide resolved
src/nested_json.rs Show resolved Hide resolved
src/nested_json.rs Outdated Show resolved Hide resolved
src/request_items.rs Outdated Show resolved Hide resolved
src/request_items.rs Outdated Show resolved Hide resolved
tests/cli.rs Show resolved Hide resolved
Copy link
Collaborator

@blyxxyz blyxxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -6,6 +6,33 @@ use anyhow::Result;
use reqwest::blocking::Request;
use url::{Host, Url};

pub fn unescape(text: &str, special_chars: &'static str) -> String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a minute to figure out that e.g. --form '\]=a' is why special_chars can have different values. Can you add a test case?

Comment on lines 384 to 390
// HTTPie currently escapes numbers regardless of whether they are between
// square brackets or not:
//
// $ http --offline --pretty=none --print=B : \\0[\\5]=x
// {"0":{"5": "x"}}
// $ xh --offline --pretty=none --print=B : \\0[\\5]=x
// {"\\0": {"5": "x"}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that it's confirmed to be a bug I'd also put a link to the issue

@ducaale ducaale merged commit 8c699cf into develop Jun 9, 2022
@ducaale ducaale deleted the nested-json branch June 9, 2022 19:18
@ducaale ducaale mentioned this pull request Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants