fix split to be html tag aware - #20
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Test asserts wrong suffix, missing actual mid-tag split
- Fixed chunkHTMLBody to fall back to splitting before the last '<' when no '>' is found (preventing mid-tag splits), and fixed the test assertion to check that the first chunk equals the pre-tag content exactly instead of checking for the wrong partial suffix.
Or push these changes by commenting:
@cursor push 2acaf74167
Preview (2acaf74167)
diff --git a/kustomer.go b/kustomer.go
--- a/kustomer.go
+++ b/kustomer.go
@@ -728,6 +728,8 @@
lastClose := strings.LastIndex(input[start:end], ">")
if lastClose != -1 {
end = start + lastClose + 1
+ } else if lastOpen := strings.LastIndex(input[start:end], "<"); lastOpen > 0 {
+ end = start + lastOpen
}
}
diff --git a/kustomer_test.go b/kustomer_test.go
--- a/kustomer_test.go
+++ b/kustomer_test.go
@@ -227,7 +227,7 @@
Expect(reassembled).To(Equal(msg))
// First chunk must end at or before the '<' of the tag
- Expect(strings.HasSuffix(chunks["htmlContent0Str"], "<stro")).To(BeFalse())
+ Expect(chunks["htmlContent0Str"]).To(Equal(before))
})
It("reassembles to the original content", func() {|
|
||
| // First chunk must end at or before the '<' of the tag | ||
| Expect(strings.HasSuffix(chunks["htmlContent0Str"], "<stro")).To(BeFalse()) | ||
| }) |
There was a problem hiding this comment.
Test asserts wrong suffix, missing actual mid-tag split
Medium Severity
The test "does not split in the middle of an HTML tag" doesn't actually verify its claim. With 1020 xs before <strong>, there's no > anywhere in input[0:1024], so lastClose is -1 and the function falls back to splitting at position 1024 — right in the middle of <strong>. The first chunk ends with <str, which IS a mid-tag split. But the assertion only checks that the suffix isn't <stro (off by one character), so the test passes despite the function doing exactly what it claims not to do.



Note
Medium Risk
Changes how outbound email HTML is segmented into Kustomer variables, which could affect rendering if edge cases (e.g., no
>near the boundary) behave unexpectedly; coverage is improved via new tests.Overview
Updates
chunkHTMLBodyto advance by variable chunk lengths and, when possible, cut each 1024-char chunk at the last>boundary so HTML tags aren’t broken across Kustomer custom variables.Adds a focused test suite covering single-chunk behavior, tag-aware splitting at boundaries, reassembly correctness, and fallback behavior when no tags are present.
Written by Cursor Bugbot for commit a44272b. This will update automatically on new commits. Configure here.