diff --git a/CHANGELOG.md b/CHANGELOG.md index dde932a2..9053066d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.2.1 (Unreleased) + +ADDITIONS + +- Add RuneCountInString check to Parse(record string) functions + ## v0.1.1 (Released 2019-06-25) BUG FIXES diff --git a/bundleControl.go b/bundleControl.go index 7458c1b5..4abcfe18 100644 --- a/bundleControl.go +++ b/bundleControl.go @@ -55,7 +55,7 @@ func NewBundleControl() *BundleControl { // Parse takes the input record string and parses the BundleControl values func (bc *BundleControl) Parse(record string) { - if utf8.RuneCountInString(record) != 80 { + if utf8.RuneCountInString(record) < 56 { return } diff --git a/bundleControl_test.go b/bundleControl_test.go index da4d3c57..2ddb7137 100644 --- a/bundleControl_test.go +++ b/bundleControl_test.go @@ -229,3 +229,14 @@ func TestFieldInclusionBundleTotalAmount(t *testing.T) { } } } + +// TestBundleControlRuneCountInString validates RuneCountInString +func TestBundleControlRuneCountInString(t *testing.T) { + bc := NewBundleControl() + var line = "70" + bc.Parse(line) + + if bc.BundleItemsCount != 0 { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/bundleHeader.go b/bundleHeader.go index d86a859c..4b8d32f5 100644 --- a/bundleHeader.go +++ b/bundleHeader.go @@ -100,7 +100,7 @@ func NewBundleHeader() *BundleHeader { // Parse takes the input record string and parses the BundleHeader values func (bh *BundleHeader) Parse(record string) { - if utf8.RuneCountInString(record) != 80 { + if utf8.RuneCountInString(record) < 68 { return } diff --git a/bundleHeader_test.go b/bundleHeader_test.go index b9691d5b..d93b9d9a 100644 --- a/bundleHeader_test.go +++ b/bundleHeader_test.go @@ -352,3 +352,14 @@ func TestBHFieldInclusionBundleSequenceNumber(t *testing.T) { } } } + +// TestBundleHeaderRuneCountInString validates RuneCountInString +func TestBundleHeaderRuneCountInString(t *testing.T) { + bh := NewBundleHeader() + var line = "20" + bh.Parse(line) + + if bh.CycleNumber != "" { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/cashLetterControl_test.go b/cashLetterControl_test.go index e7049065..c79d9fed 100644 --- a/cashLetterControl_test.go +++ b/cashLetterControl_test.go @@ -217,3 +217,14 @@ func TestFieldInclusionRecordTypeSettlementDate(t *testing.T) { } } } + +// TestCashLetterControlRuneCountInString validates RuneCountInString +func TestCashLetterControlRuneCountInString(t *testing.T) { + clc := NewCashLetterControl() + var line = "90" + clc.Parse(line) + + if clc.CashLetterBundleCount != 0 { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/cashLetterHeader_test.go b/cashLetterHeader_test.go index a5a2d2e3..dba746a6 100644 --- a/cashLetterHeader_test.go +++ b/cashLetterHeader_test.go @@ -440,3 +440,14 @@ func TestFieldInclusionCashLetterID(t *testing.T) { } } } + +// TestCashLetterHeaderRuneCountInString validates RuneCountInString +func TestCashLetterHeaderRuneCountInString(t *testing.T) { + clh := NewCashLetterHeader() + var line = "10" + clh.Parse(line) + + if clh.CollectionTypeIndicator != "" { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/fileControl.go b/fileControl.go index 349bc82e..93e0b99e 100644 --- a/fileControl.go +++ b/fileControl.go @@ -7,6 +7,7 @@ package imagecashletter import ( "fmt" "strings" + "unicode/utf8" ) // FileControl Record @@ -54,6 +55,9 @@ func NewFileControl() FileControl { // Parse takes the input record string and parses the FileControl values func (fc *FileControl) Parse(record string) { + if utf8.RuneCountInString(record) < 65 { + return + } // Character position 1-2, Always "99" fc.recordType = "99" // 03-08 diff --git a/fileControl_test.go b/fileControl_test.go index 1c0604d1..dc7d72d1 100644 --- a/fileControl_test.go +++ b/fileControl_test.go @@ -254,3 +254,14 @@ func TestFieldInclusionFileTotalAmount(t *testing.T) { } } } + +// TestFileControlRuneCountInString validates RuneCountInString +func TestFileControlRuneCountInString(t *testing.T) { + fc := NewFileControl() + var line = "99" + fc.Parse(line) + + if fc.CashLetterCount != 0 { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/fileHeader.go b/fileHeader.go index c3adaa38..6379c51b 100644 --- a/fileHeader.go +++ b/fileHeader.go @@ -8,6 +8,7 @@ import ( "fmt" "strings" "time" + "unicode/utf8" ) // FileHeader Record is mandatory @@ -103,6 +104,9 @@ func NewFileHeader() FileHeader { // Parse takes the input record string and parses the FileHeader values func (fh *FileHeader) Parse(record string) { + if utf8.RuneCountInString(record) != 80 { + return + } // Character position 1-2, Always "01" fh.recordType = "01" // 03-04 diff --git a/fileHeader_test.go b/fileHeader_test.go index 684ed1db..b3a78a8d 100644 --- a/fileHeader_test.go +++ b/fileHeader_test.go @@ -445,3 +445,14 @@ func TestFHFieldInclusionCreationTime(t *testing.T) { } } } + +// TestFileHeaderRuneCountInString validates RuneCountInString +func TestFileHeaderRuneCountInString(t *testing.T) { + fh := NewFileHeader() + var line = "01" + fh.Parse(line) + + if fh.ImmediateOrigin != "" { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/go.sum b/go.sum index 98fc46d5..e3102439 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0 h1:8HUsc87TaSWLKwrnumgC8/YconD2fJQsRJAsWaPg2ic= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -23,6 +24,7 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/gorilla/mux v1.7.2 h1:zoNxOV7WjqXptQOVngLmcSQgXmgk4NMz1HibBchjl/I= github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= diff --git a/imageViewAnalysis_test.go b/imageViewAnalysis_test.go index 96a222ae..2417b544 100644 --- a/imageViewAnalysis_test.go +++ b/imageViewAnalysis_test.go @@ -518,3 +518,14 @@ func TestIVAnalysisFIRecordType(t *testing.T) { } } } + +// TestIVAnalysisRuneCountInString validates RuneCountInString +func TestIVAnalysisRuneCountInString(t *testing.T) { + ivAnalysis := NewImageViewAnalysis() + var line = "54" + ivAnalysis.Parse(line) + + if ivAnalysis.AmountInWordsUsability != 0 { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/imageViewDetail_test.go b/imageViewDetail_test.go index ac33276e..f15f5da7 100644 --- a/imageViewDetail_test.go +++ b/imageViewDetail_test.go @@ -421,3 +421,14 @@ func TestIVDetailFIViewDescriptor(t *testing.T) { } } } + +// TestIVDetailRuneCountInString validates RuneCountInString +func TestIVDetailRuneCountInString(t *testing.T) { + ivDetail := NewImageViewDetail() + var line = "50" + ivDetail.Parse(line) + + if ivDetail.ImageCreatorRoutingNumber != "" { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/returnDetailAddendumC_test.go b/returnDetailAddendumC_test.go index a3d87a38..fb86c534 100644 --- a/returnDetailAddendumC_test.go +++ b/returnDetailAddendumC_test.go @@ -246,3 +246,14 @@ func TestRDAddendumCFIMicrofilmArchiveSequenceNumber(t *testing.T) { } } } + +// TestRDAddendumCRuneCountInString validates RuneCountInString +func TestRDAddendumCRuneCountInString(t *testing.T) { + rdAddendumC := NewReturnDetailAddendumC() + var line = "34" + rdAddendumC.Parse(line) + + if rdAddendumC.Description != "" { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/returnDetailAddendumD_test.go b/returnDetailAddendumD_test.go index 565a86e2..47501b71 100644 --- a/returnDetailAddendumD_test.go +++ b/returnDetailAddendumD_test.go @@ -368,3 +368,14 @@ func TestRDAddendumDFITruncationIndicator(t *testing.T) { } } } + +// TestRDAddendumDRuneCountInString validates RuneCountInString +func TestRDAddendumDRuneCountInString(t *testing.T) { + rdAddendumD := NewReturnDetailAddendumD() + var line = "35" + rdAddendumD.Parse(line) + + if rdAddendumD.EndorsingBankRoutingNumber != "" { + t.Error("Parsed with an invalid RuneCountInString") + } +} diff --git a/userPayeeEndorsement_test.go b/userPayeeEndorsement_test.go index fe535ad4..da7183d9 100644 --- a/userPayeeEndorsement_test.go +++ b/userPayeeEndorsement_test.go @@ -522,3 +522,14 @@ func TestUPEFILengthUserData(t *testing.T) { } } } + +// TestUPERuneCountInString validates RuneCountInString +func TestUPERuneCountInString(t *testing.T) { + upe := NewUserPayeeEndorsement() + var line = "68" + upe.Parse(line) + + if upe.BankAccountNumber != "" { + t.Error("Parsed with an invalid RuneCountInString") + } +}