Skip to content

fix split to be html tag aware - #20

Merged
dselans merged 1 commit into
mainfrom
dselans/split-fix
Mar 10, 2026
Merged

fix split to be html tag aware#20
dselans merged 1 commit into
mainfrom
dselans/split-fix

Conversation

@dselans

@dselans dselans commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

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 chunkHTMLBody to 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.

@dselans
dselans merged commit 2a3636e into main Mar 10, 2026
1 of 2 checks passed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Create PR

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() {

Comment thread kustomer_test.go

// First chunk must end at or before the '<' of the tag
Expect(strings.HasSuffix(chunks["htmlContent0Str"], "<stro")).To(BeFalse())
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant