Repository navigation
Make json require string and pass around metadata - #7010
Conversation
1089308 to
3a310c2
Compare
|
One question that came up on Discord is whether this should be more general. It seems like many different |
Oh, good point, I started with json but I will be happy to look at others (should I put them in this PR or another one?) I'm also thinking of adding some more parsers for other formats and maybe they will use the method as well. (But I want to make them streaming.) |
|
Ah, good catch. I also noticed this today, with xml: |
I think doing it in this PR makes sense, unless it turns out to be more work than expected. |
|
OK, I will look into it. Hopefully later today. |
|
I pushed a commit fixing the other commands but didn't have time to test properly yet. I should be able to test tomorrow but feel free to give it a go in the meantime if you want. |
|
@Kixunil How's this PR coming? Will you be able to get back to it soon? |
The json deserializer was accepting any inputs by coercing non-strings into strings. As an example, if the input was `[1, 2]` the coercion would turn into `[12]` and deserialize as a list containing number twelve instead of a list of two numbers, one and two. This could lead to silent data corruption. Aside from that pipeline metadata wasn't passed aroud. This commit fixes the type issue by adding a strict conversion function that errors if the input type is not a string or external stream. It then uses this function instead of the original `collect_string()`. In addition, this function returns the pipeline metadata so it can be passed along.
c4730b8 to
189a48e
Compare
|
Thanks for the ping, I didn't have time but I just got some. :) |
The problem with json coercing non-string types to string was present in all other text formats. This reuses the `collect_string_strict` function to fix them.
The method `into_pipeline_data_with_metadata` can now be conveniently used.
189a48e to
a27ffd5
Compare
|
The tests pass now. 🎉 |
|
This is an awesome change, thanks! I'm reading through the code and giving it a try, looks good so far and we should be able to merge it soon. |
|
This looks super. Did some manual testing and it works nicely. |


The json deserializer was accepting any inputs by coercing non-strings into strings. As an example, if the input was
[1, 2]the coercion would turn into[12]and deserialize as a list containing number twelve instead of a list of two numbers, one and two. This could lead to silent data corruption.Aside from that pipeline metadata wasn't passed aroud.
This commit fixes the type issue by adding a strict conversion function that errors if the input type is not a string or external stream. It then uses this function instead of the original
collect_string(). In addition, this function returns the pipeline metadata so it can be passed along.Description
(Description of your pull request goes here. Provide examples and/or screenshots unless the change is trivial)
Tests + Formatting
Make sure you've done the following, if applicable:
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspace --features=extrato check that all tests passUser-Facing Changes
If you're making changes that will affect the user experience of Nushell (ex: adding/removing a command, changing an input/output type, adding a new flag):