From 890b256763820de93994480d3c4bb4a5cd4c8b24 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Thu, 2 Apr 2026 05:57:07 +0000 Subject: [PATCH] fix(builtins): honor jq -j/--join-output flag to suppress trailing newline The -j flag was correctly suppressing newlines between outputs but the trailing-newline enforcement at the end of output was not checking the join_output flag. Check join_output and skip the trailing newline when set. Closes #951 --- crates/bashkit/src/builtins/jq.rs | 5 +++-- crates/bashkit/tests/spec_cases/jq/jq.test.sh | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/bashkit/src/builtins/jq.rs b/crates/bashkit/src/builtins/jq.rs index c8aabd0c..64a15f8e 100644 --- a/crates/bashkit/src/builtins/jq.rs +++ b/crates/bashkit/src/builtins/jq.rs @@ -672,8 +672,9 @@ impl Builtin for Jq { } } - // Ensure output ends with newline if there's output (for consistency) - if !output.is_empty() && !output.ends_with('\n') { + // Ensure output ends with newline if there's output (for consistency), + // but not when -j/--join-output is set (it suppresses trailing newline). + if !join_output && !output.is_empty() && !output.ends_with('\n') { output.push('\n'); } diff --git a/crates/bashkit/tests/spec_cases/jq/jq.test.sh b/crates/bashkit/tests/spec_cases/jq/jq.test.sh index 57688530..87a07a45 100644 --- a/crates/bashkit/tests/spec_cases/jq/jq.test.sh +++ b/crates/bashkit/tests/spec_cases/jq/jq.test.sh @@ -829,8 +829,9 @@ echo '{"a":1}' | jq --tab '.' ### end ### jq_join_output -# Join output mode suppresses newlines between outputs +# Join output mode suppresses newlines between and after outputs echo '["a","b"]' | jq -j '.[]' +printf '\n' ### expect ab ### end