Skip to content

Commit 6f916d6

Browse files
committed
fix(lib): fix logic error where we join first then processed intead of processing then joining
1 parent e63bdd4 commit 6f916d6

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

src/pipeline/template.rs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -699,23 +699,41 @@ impl MultiTemplate {
699699
return Err("Internal error: template index out of bounds".to_string());
700700
}
701701

702-
// Join multiple inputs with the corresponding separator
702+
// Process each input individually, then join the results
703703
let section_inputs = inputs[template_index];
704704
let separator = separators[template_index];
705-
let input = match section_inputs.len() {
705+
let output = match section_inputs.len() {
706706
0 => String::new(),
707-
1 => section_inputs[0].to_string(),
708-
_ => section_inputs.join(separator),
707+
1 => {
708+
let mut input_hasher = std::collections::hash_map::DefaultHasher::new();
709+
std::hash::Hash::hash(&section_inputs[0], &mut input_hasher);
710+
let input_hash = input_hasher.finish();
711+
712+
self.apply_template_section(
713+
section_inputs[0],
714+
ops,
715+
input_hash,
716+
&mut cache,
717+
&None, // No debug tracing for structured processing
718+
)?
719+
}
720+
_ => {
721+
let mut results = Vec::new();
722+
for input in section_inputs {
723+
let mut input_hasher =
724+
std::collections::hash_map::DefaultHasher::new();
725+
std::hash::Hash::hash(&input, &mut input_hasher);
726+
let input_hash = input_hasher.finish();
727+
728+
let result = self.apply_template_section(
729+
input, ops, input_hash, &mut cache,
730+
&None, // No debug tracing for structured processing
731+
)?;
732+
results.push(result);
733+
}
734+
results.join(separator)
735+
}
709736
};
710-
711-
let mut input_hasher = std::collections::hash_map::DefaultHasher::new();
712-
std::hash::Hash::hash(&input, &mut input_hasher);
713-
let input_hash = input_hasher.finish();
714-
715-
let output = self.apply_template_section(
716-
&input, ops, input_hash, &mut cache,
717-
&None, // No debug tracing for structured processing
718-
)?;
719737
result.push_str(&output);
720738
template_index += 1;
721739
}

tests/multi_template_tests.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,19 @@ fn test_structured_template_complex_scenario() {
582582
let result = template
583583
.format_with_inputs(
584584
&[
585-
&["/home/user/documents/important.txt"],
585+
&[
586+
"/home/user/documents/important1.txt",
587+
"/home/user/documents/important2.txt",
588+
],
586589
&["/home/user/documents/important.txt"],
587590
],
588591
&[" ", " "],
589592
)
590593
.unwrap();
591-
assert_eq!(result, "cp important.txt /backup/important.bak");
594+
assert_eq!(
595+
result,
596+
"cp important1.txt important2.txt /backup/important.bak"
597+
);
592598
}
593599

594600
#[test]

0 commit comments

Comments
 (0)