Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/bashkit/src/builtins/jq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ impl Builtin for Jq {
};

// If no input and not null_input mode, return empty
if input.trim().is_empty() && !null_input {
// (but not for -Rs: raw_input+slurp should produce "" for empty stdin)
if input.trim().is_empty() && !null_input && !(raw_input && slurp) {
return Ok(ExecResult::ok(String::new()));
}

Expand Down Expand Up @@ -1361,6 +1362,13 @@ mod tests {
assert!(result.contains("1,2,3"));
}

#[tokio::test]
async fn test_jq_raw_input_slurp_empty_stdin() {
// -Rs on empty stdin should produce "" (empty JSON string), not nothing
let result = run_jq_with_args(&["-Rs", "."], "").await.unwrap();
assert_eq!(result.trim(), "\"\"");
}

// --- Process env pollution tests (issue #410) ---

#[tokio::test]
Expand Down
14 changes: 14 additions & 0 deletions crates/bashkit/tests/spec_cases/jq/jq.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1000,3 +1000,17 @@ printf 'a,b\n1,2\n' | jq -Rs 'split("\n") | map(select(length>0))'
"1,2"
]
### end

### jq_raw_slurp_empty_stdin
# jq -Rs on empty stdin should produce empty JSON string
printf '' | jq -Rs '.'
### expect
""
### end

### jq_raw_slurp_normal
# jq -Rs on normal input (no regression)
printf 'hello' | jq -Rs '.'
### expect
"hello"
### end
Loading