diff options
author | Dan Meyers <daniel_meyers@brown.edu> | 2017-06-10 13:54:41 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@gmail.com> | 2017-06-10 13:54:41 -0400 |
commit | ed00acdb054d3e26b9a2ffdb09fdd94585bab65d (patch) | |
tree | 59af6ab6a2a1f8686e86daa9fd9d79f6e9ec8a83 /contrib | |
parent | 1479a09a479583e62b9ed4b6d1636e58fff91e13 (diff) |
prevent panic when registering barcode fails (#118)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/barcode/barcode.go | 10 | ||||
-rw-r--r-- | contrib/barcode/barcode_test.go | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/contrib/barcode/barcode.go b/contrib/barcode/barcode.go index 63a4908..9f8d3ff 100644 --- a/contrib/barcode/barcode.go +++ b/contrib/barcode/barcode.go @@ -20,6 +20,11 @@ package barcode import ( "bytes" "errors" + "image/jpeg" + "io" + "strconv" + "sync" + "github.com/boombuler/barcode" "github.com/boombuler/barcode/aztec" "github.com/boombuler/barcode/codabar" @@ -31,10 +36,6 @@ import ( "github.com/boombuler/barcode/twooffive" "github.com/jung-kurt/gofpdf" "github.com/ruudk/golang-pdf417" - "image/jpeg" - "io" - "strconv" - "sync" ) // barcodes represents the barcodes that have been registered through this @@ -197,6 +198,7 @@ func RegisterTwoOfFive(pdf barcodePdf, code string, interleaved bool) string { func registerBarcode(pdf barcodePdf, bcode barcode.Barcode, err error) string { if err != nil { pdf.SetError(err) + return "" } return Register(bcode) diff --git a/contrib/barcode/barcode_test.go b/contrib/barcode/barcode_test.go index c3c648c..5b6c8cf 100644 --- a/contrib/barcode/barcode_test.go +++ b/contrib/barcode/barcode_test.go @@ -1,6 +1,8 @@ package barcode_test import ( + "testing" + "github.com/boombuler/barcode/code128" "github.com/boombuler/barcode/qr" "github.com/jung-kurt/gofpdf" @@ -150,3 +152,9 @@ func ExampleRegisterPdf417() { // Output: // Successfully generated ../../pdf/contrib_barcode_RegisterPdf417.pdf } + +// This test ensures that no panic arises when an invalid barcode is registered. +func TestRegisterCode128(t *testing.T) { + pdf := createPdf() + barcode.RegisterCode128(pdf, "Invalid character: é") +} |