diff --git a/pkg/interp/interp.jq b/pkg/interp/interp.jq index ab2eba34..4b290856 100644 --- a/pkg/interp/interp.jq +++ b/pkg/interp/interp.jq @@ -473,25 +473,30 @@ def input: end else ( [_repeat_break(_input($opts; tobytes | tostring))] - | join("") as $all + | . as $chunks | if $opts.slurp then # jq --raw-input combined with --slurp reads all inputs into a string # make next input break ( _input_strings_lines([]) as $_ - | $all + | $chunks + | join("") ) else # TODO: different line endings? # jq strips last newline, "a\nb" and "a\nb\n" behaves the same # also jq -R . <(echo -ne 'a\nb') <(echo c) produces "a" and "bc" - ( _input_strings_lines( - ( $all - | rtrimstr("\n") - | split("\n") - ) - ) as $_ - | input - ) + if ($chunks | length) > 0 then + ( _input_strings_lines( + ( $chunks + | join("") + | rtrimstr("\n") + | split("\n") + ) + ) as $_ + | input + ) + else error("break") + end end ) end diff --git a/pkg/interp/testdata/string_input.fqtest b/pkg/interp/testdata/string_input.fqtest index 5edff192..756e9cd1 100644 --- a/pkg/interp/testdata/string_input.fqtest +++ b/pkg/interp/testdata/string_input.fqtest @@ -54,3 +54,12 @@ stdin: a b c +$ fq -R . missing +exitcode: 2 +stderr: +error: missing: file not found +$ fq -Rs . missing +"" +exitcode: 2 +stderr: +error: missing: file not found