Skip to content

Commit 250e9db

Browse files
committed
Ensure that the exact block size match is not skipped and added test
1 parent d4f95a9 commit 250e9db

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

transform/encode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func EncodeBase64Chunks(s string, maxChunkSize uint) []string {
9494
// the chunk size calculation iterates to the best block size.
9595
chunkSize := (len(s) / int(maxChunkSize)) - (len(s) / int(maxChunkSize) / 3) - 1
9696
for {
97-
if maxSize(chunkSize) >= int(maxChunkSize) {
97+
if maxSize(chunkSize) > int(maxChunkSize) {
9898
chunkSize--
9999

100100
break

transform/encode_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ func TestEncodeBase64Chunks(t *testing.T) {
3838
}
3939

4040
t.Log(chunks)
41+
42+
chunks = EncodeBase64Chunks("1234567890123456789012345678901234567890", 12)
43+
expected = []string{"MTIzNDU2Nzg5", "MDEyMzQ1Njc4", "OTAxMjM0NTY3", "ODkwMTIzNDU2", "Nzg5MA=="}
44+
for i, c := range chunks {
45+
if c != expected[i] {
46+
t.Fatal(chunks)
47+
}
48+
}
49+
50+
t.Log(chunks)
51+
52+
chunks = EncodeBase64Chunks("1234567890123456789012345678901234567890", 13)
53+
for i, c := range chunks {
54+
if c != expected[i] {
55+
t.Fatal(chunks)
56+
}
57+
}
58+
59+
t.Log(chunks)
4160
}
4261

4362
func TestEncodeBase64Chunks_EmptyString(t *testing.T) {

0 commit comments

Comments
 (0)