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

Fix for #2374 #2375

Closed
wants to merge 2 commits into from
Closed

Fix for #2374 #2375

wants to merge 2 commits into from

Conversation

eddyashton
Copy link

See #2374 for explanation of the issue.

I've poked around the code and found this possible fix. It's not very neat (checking state->current_input and modifying state->current_line outside of jq_util_input_read_more), but it works and doesn't break any other tests. Please feel free to propose a neater fix if you can see one.

I've also added a regression test. This uses a bunch of functions, so perhaps shouldn't be in shtest? But I don't see input_line_number tested anywhere else.

@owenthereal
Copy link
Member

LGTM

@nicowilliams
Copy link
Contributor

This needs to be a command-line option. As @pkoppstein explained in #2374, this would be an incompatible change.

@nicowilliams
Copy link
Contributor

You can probably use input_filename in a reduction (reduce or foreach) over inputs to detect when jq has moved from reading from one file to the next.

@eddyashton
Copy link
Author

As @pkoppstein explained in #2374, this change breaks backwards compatibility. Closing for now, will revisit as an additional commandline if I get time.

@eddyashton eddyashton closed this May 26, 2022
@emanuele6
Copy link
Member

emanuele6 commented Oct 3, 2023

I don't think it matters that fixing this bug "breaks backward compatibility".
The current behaviour is not good, and lets input_filename/0 and input_line_number/0 return values that are wrong.

I think this fix should be merged.

The fix looks good, but there a merge conflict in shtest.

@emanuele6
Copy link
Member

Actually, this patch does not fix the issue fully correctly.

If you use --slurp --raw-input, it will stop slurping after the end of the first non-empty file that does not have a final newline, and start reading the rest of the inputs line by line (though still not merging content of different files into one string):

$ printf foo\\n > foo; printf bar > bar; printf baz1\\nbaz2\\n > baz; printf xyz > xyz; printf hello > hello
$ jq -sR . foo bar baz xyz hello
"foo\nbar"
"baz1"
"baz2"
"xyz"
"hello"

@emanuele6
Copy link
Member

And this problem also occurs for files in non-raw mode:

$ jq . <(printf 4) <(echo 5)
45

@nicowilliams nicowilliams reopened this Oct 3, 2023
@nicowilliams
Copy link
Contributor

Let's fix this in a separate PR.

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.

5 participants