Skip to content

Commit b8acca2

Browse files
committed
zpay32: test case for parsing non UTF-8 description
1 parent 2b1a89f commit b8acca2

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

zpay32/invoice_internal_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,25 @@ func TestParse32Bytes(t *testing.T) {
369369
func TestParseDescription(t *testing.T) {
370370
t.Parallel()
371371

372+
testNonUTF8StrData, _ := bech32.ConvertBits(
373+
[]byte(testNonUTF8Str), 8, 5, true,
374+
)
375+
372376
testCupOfCoffeeData, _ := bech32.ConvertBits([]byte(testCupOfCoffee), 8, 5, true)
373377
testPleaseConsiderData, _ := bech32.ConvertBits([]byte(testPleaseConsider), 8, 5, true)
374378

375379
tests := []struct {
376-
data []byte
377-
valid bool
378-
result *string
380+
data []byte
381+
valid bool
382+
result *string
383+
expectedErr error
379384
}{
385+
{
386+
data: testNonUTF8StrData,
387+
valid: false,
388+
expectedErr: ErrInvalidUTF8Description,
389+
result: nil,
390+
},
380391
{
381392
data: []byte{},
382393
valid: true,
@@ -400,6 +411,7 @@ func TestParseDescription(t *testing.T) {
400411
t.Errorf("description decoding test %d failed: %v", i, err)
401412
return
402413
}
414+
require.ErrorIs(t, err, test.expectedErr)
403415
if test.valid && !reflect.DeepEqual(description, test.result) {
404416
t.Fatalf("test %d failed decoding description: "+
405417
"expected \"%s\", got \"%s\"",

zpay32/invoice_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var (
5050
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
5151
}
5252

53+
testNonUTF8Str = "1 cup coffee\xff\xfe\xfd"
5354
testEmptyString = ""
5455
testCupOfCoffee = "1 cup coffee"
5556
testCoffeeBeans = "coffee beans"

0 commit comments

Comments
 (0)