diff --git a/accountCreditedDrawdown.go b/accountCreditedDrawdown.go index 14ff8bba..87e3ee24 100644 --- a/accountCreditedDrawdown.go +++ b/accountCreditedDrawdown.go @@ -50,7 +50,7 @@ func (creditDD *AccountCreditedDrawdown) Parse(record string) error { creditDD.DrawdownCreditAccountNumber = value length += read - if len(record) != length { + if !creditDD.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/accountDebitedDrawdown.go b/accountDebitedDrawdown.go index 10d339ba..77fe8a73 100644 --- a/accountDebitedDrawdown.go +++ b/accountDebitedDrawdown.go @@ -84,7 +84,7 @@ func (debitDD *AccountDebitedDrawdown) Parse(record string) error { debitDD.Address.AddressLineThree = value length += read - if len(record) != length { + if !debitDD.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/actualAmountPaid.go b/actualAmountPaid.go index fb5162f6..e94f3a76 100644 --- a/actualAmountPaid.go +++ b/actualAmountPaid.go @@ -57,7 +57,7 @@ func (aap *ActualAmountPaid) Parse(record string) error { aap.RemittanceAmount.Amount = value length += read - if len(record) != length { + if !aap.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/actualAmountPaid_test.go b/actualAmountPaid_test.go index 8290661b..080e96a4 100644 --- a/actualAmountPaid_test.go +++ b/actualAmountPaid_test.go @@ -117,7 +117,7 @@ func TestStringActualAmountPaidVariableLength(t *testing.T) { err = r.parseActualAmountPaid() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{8450}***" + line = "{8450}****" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/adjustment.go b/adjustment.go index 9bccfaf1..117f7494 100644 --- a/adjustment.go +++ b/adjustment.go @@ -84,7 +84,7 @@ func (adj *Adjustment) Parse(record string) error { adj.AdditionalInfo = value length += read - if len(record) != length { + if !adj.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/adjustment_test.go b/adjustment_test.go index cedadd78..c95d2898 100644 --- a/adjustment_test.go +++ b/adjustment_test.go @@ -160,7 +160,7 @@ func TestStringAdjustmentVariableLength(t *testing.T) { err = r.parseAdjustment() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{8600}01CRDTUSD1234.56***" + line = "{8600}01CRDTUSD1234.56****" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/amountNegotiatedDiscount.go b/amountNegotiatedDiscount.go index 8d16e4ef..e71076a0 100644 --- a/amountNegotiatedDiscount.go +++ b/amountNegotiatedDiscount.go @@ -57,7 +57,7 @@ func (nd *AmountNegotiatedDiscount) Parse(record string) error { nd.RemittanceAmount.Amount = value length += read - if len(record) != length { + if !nd.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/amountNegotiatedDiscount_test.go b/amountNegotiatedDiscount_test.go index dc655225..222f52eb 100644 --- a/amountNegotiatedDiscount_test.go +++ b/amountNegotiatedDiscount_test.go @@ -117,7 +117,7 @@ func TestStringAmountNegotiatedDiscountVariableLength(t *testing.T) { err = r.parseAmountNegotiatedDiscount() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{8550}USD1234.56**" + line = "{8550}USD1234.56***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/beneficiary.go b/beneficiary.go index 1f5cd4d1..0d8e7a88 100644 --- a/beneficiary.go +++ b/beneficiary.go @@ -79,7 +79,7 @@ func (ben *Beneficiary) Parse(record string) error { ben.Personal.Address.AddressLineThree = value length += read - if len(record) != length { + if !ben.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/beneficiaryCustomer.go b/beneficiaryCustomer.go index 0edd7191..761e9e15 100644 --- a/beneficiaryCustomer.go +++ b/beneficiaryCustomer.go @@ -85,7 +85,7 @@ func (bc *BeneficiaryCustomer) Parse(record string) error { bc.CoverPayment.SwiftLineFive = value length += read - if len(record) != length { + if !bc.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/beneficiaryCustomer_test.go b/beneficiaryCustomer_test.go index 7bf1e29a..b12a6ee0 100644 --- a/beneficiaryCustomer_test.go +++ b/beneficiaryCustomer_test.go @@ -150,7 +150,7 @@ func TestStringBeneficiaryCustomerVariableLength(t *testing.T) { err = r.parseBeneficiaryCustomer() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{7059}*******" + line = "{7059}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/beneficiaryFI.go b/beneficiaryFI.go index b229b572..bbf4621b 100644 --- a/beneficiaryFI.go +++ b/beneficiaryFI.go @@ -79,7 +79,7 @@ func (bfi *BeneficiaryFI) Parse(record string) error { bfi.FinancialInstitution.Address.AddressLineThree = value length += read - if len(record) != length { + if !bfi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/beneficiaryFI_test.go b/beneficiaryFI_test.go index 23cb06b3..014765ac 100644 --- a/beneficiaryFI_test.go +++ b/beneficiaryFI_test.go @@ -171,7 +171,7 @@ func TestStringBeneficiaryFIVariableLength(t *testing.T) { err = r.parseBeneficiaryFI() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{4100}D123456789******" + line = "{4100}D123456789*******" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/beneficiaryIntermediaryFI.go b/beneficiaryIntermediaryFI.go index d33ed342..74bab998 100644 --- a/beneficiaryIntermediaryFI.go +++ b/beneficiaryIntermediaryFI.go @@ -79,7 +79,7 @@ func (bifi *BeneficiaryIntermediaryFI) Parse(record string) error { bifi.FinancialInstitution.Address.AddressLineThree = value length += read - if len(record) != length { + if !bifi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/beneficiaryIntermediaryFI_test.go b/beneficiaryIntermediaryFI_test.go index 65d12bc0..d08de6ab 100644 --- a/beneficiaryIntermediaryFI_test.go +++ b/beneficiaryIntermediaryFI_test.go @@ -174,7 +174,7 @@ func TestStringBeneficiaryIntermediaryFIVariableLength(t *testing.T) { err = r.parseBeneficiaryIntermediaryFI() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{4000}D123456789******" + line = "{4000}D123456789*******" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/beneficiaryReference.go b/beneficiaryReference.go index a5b48b10..c58757af 100644 --- a/beneficiaryReference.go +++ b/beneficiaryReference.go @@ -50,7 +50,7 @@ func (br *BeneficiaryReference) Parse(record string) error { br.BeneficiaryReference = value length += read - if len(record) != length { + if !br.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/beneficiaryReference_test.go b/beneficiaryReference_test.go index 4cc7c795..2a971dc3 100644 --- a/beneficiaryReference_test.go +++ b/beneficiaryReference_test.go @@ -85,7 +85,7 @@ func TestStringBeneficiaryReferenceVariableLength(t *testing.T) { err = r.parseBeneficiaryReference() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{4320}**" + line = "{4320}***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/beneficiary_test.go b/beneficiary_test.go index 2708a1a3..1a8a1f20 100644 --- a/beneficiary_test.go +++ b/beneficiary_test.go @@ -161,7 +161,7 @@ func TestStringBeneficiaryVariableLength(t *testing.T) { err = r.parseBeneficiary() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{4200}31234******" + line = "{4200}31234*******" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/businessFunctionCode.go b/businessFunctionCode.go index 0b9eca0a..106d5985 100644 --- a/businessFunctionCode.go +++ b/businessFunctionCode.go @@ -53,7 +53,7 @@ func (bfc *BusinessFunctionCode) Parse(record string) error { bfc.TransactionTypeCode = value length += read - if len(record) != length { + if !bfc.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/businessFunctionCode_test.go b/businessFunctionCode_test.go index 15700a77..8b150c5b 100644 --- a/businessFunctionCode_test.go +++ b/businessFunctionCode_test.go @@ -97,7 +97,7 @@ func TestStringBusinessFunctionCodeVariableLength(t *testing.T) { err = r.parseBusinessFunctionCode() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{3600}BTR**" + line = "{3600}BTR***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/charges.go b/charges.go index 27e1d8a7..4c9c84fd 100644 --- a/charges.go +++ b/charges.go @@ -88,7 +88,7 @@ func (c *Charges) Parse(record string) error { c.SendersChargesFour = value length += read - if len(record) != length { + if !c.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/charges_test.go b/charges_test.go index 458761a5..e4cabdff 100644 --- a/charges_test.go +++ b/charges_test.go @@ -60,7 +60,7 @@ func TestStringChargesVariableLength(t *testing.T) { err = r.parseCharges() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{3700}B*****" + line = "{3700}B******" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/converters.go b/converters.go index d8297ea9..655da48c 100644 --- a/converters.go +++ b/converters.go @@ -142,3 +142,16 @@ func (c *converters) stripDelimiters(data string) string { return data[:index] } + +// verify input data with read length +func (c *converters) verifyDataWithReadLength(data string, read int) bool { + if len(data) == read { + return true + } + + if len(data) > read && data[read:] == "*" { + return true + } + + return false +} diff --git a/currencyInstructedAmount.go b/currencyInstructedAmount.go index 63a5537b..e78de8f1 100644 --- a/currencyInstructedAmount.go +++ b/currencyInstructedAmount.go @@ -60,7 +60,7 @@ func (cia *CurrencyInstructedAmount) Parse(record string) error { cia.Amount = cia.parseStringField(record[length : length+18]) length += 18 - if len(record) != length { + if !cia.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/errorWire.go b/errorWire.go index bde0046d..78c57b8b 100644 --- a/errorWire.go +++ b/errorWire.go @@ -68,7 +68,7 @@ func (ew *ErrorWire) Parse(record string) error { ew.ErrorDescription = value length += read - if len(record) != length { + if !ew.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/errorWire_test.go b/errorWire_test.go index b0964356..45ec979d 100644 --- a/errorWire_test.go +++ b/errorWire_test.go @@ -65,7 +65,7 @@ func TestStringErrorWireAmountVariableLength(t *testing.T) { err = r.parseErrorWire() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{1130}1XYZData Error**" + line = "{1130}1XYZData Error***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/exchangeRate.go b/exchangeRate.go index 2b20d7b0..0bbd0a31 100644 --- a/exchangeRate.go +++ b/exchangeRate.go @@ -51,7 +51,7 @@ func (eRate *ExchangeRate) Parse(record string) error { eRate.ExchangeRate = value length += read - if len(record) != length { + if !eRate.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/exchangeRate_test.go b/exchangeRate_test.go index b0a3426f..d0d9fcd8 100644 --- a/exchangeRate_test.go +++ b/exchangeRate_test.go @@ -87,7 +87,7 @@ func TestStringErrorExchangeRateVariableLength(t *testing.T) { err = r.parseExchangeRate() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{3720}123**" + line = "{3720}123***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fIBeneficiaryFIAdvice.go b/fIBeneficiaryFIAdvice.go index 45763b39..f4d84fd5 100644 --- a/fIBeneficiaryFIAdvice.go +++ b/fIBeneficiaryFIAdvice.go @@ -86,7 +86,7 @@ func (fibfia *FIBeneficiaryFIAdvice) Parse(record string) error { fibfia.Advice.LineSix = value length += read - if len(record) != length { + if !fibfia.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fIBeneficiaryFIAdvice_test.go b/fIBeneficiaryFIAdvice_test.go index 6ff2b1b8..3a60fe92 100644 --- a/fIBeneficiaryFIAdvice_test.go +++ b/fIBeneficiaryFIAdvice_test.go @@ -151,7 +151,7 @@ func TestStringFIBeneficiaryFIAdviceVariableLength(t *testing.T) { err = r.parseFIBeneficiaryFIAdvice() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6310}HLD*******" + line = "{6310}HLD********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiAdditionalFIToFI.go b/fiAdditionalFIToFI.go index f38f7631..803ea6b0 100644 --- a/fiAdditionalFIToFI.go +++ b/fiAdditionalFIToFI.go @@ -85,7 +85,7 @@ func (fifi *FIAdditionalFIToFI) Parse(record string) error { fifi.AdditionalFIToFI.LineSix = value length += read - if len(record) != length { + if !fifi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiAdditionalFIToFI_test.go b/fiAdditionalFIToFI_test.go index dc56a990..347bc3ce 100644 --- a/fiAdditionalFIToFI_test.go +++ b/fiAdditionalFIToFI_test.go @@ -139,7 +139,7 @@ func TestStringFIAdditionalFIToFIVariableLength(t *testing.T) { err = r.parseFIAdditionalFIToFI() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6500}*******" + line = "{6500}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiBeneficiary.go b/fiBeneficiary.go index 10a9902e..98c48b39 100644 --- a/fiBeneficiary.go +++ b/fiBeneficiary.go @@ -85,7 +85,7 @@ func (fib *FIBeneficiary) Parse(record string) error { fib.FIToFI.LineSix = value length += read - if len(record) != length { + if !fib.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiBeneficiaryAdvice.go b/fiBeneficiaryAdvice.go index bcb41f18..25c444a1 100644 --- a/fiBeneficiaryAdvice.go +++ b/fiBeneficiaryAdvice.go @@ -86,7 +86,7 @@ func (fiba *FIBeneficiaryAdvice) Parse(record string) error { fiba.Advice.LineSix = value length += read - if len(record) != length { + if !fiba.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiBeneficiaryAdvice_test.go b/fiBeneficiaryAdvice_test.go index 28dd8988..f08d1581 100644 --- a/fiBeneficiaryAdvice_test.go +++ b/fiBeneficiaryAdvice_test.go @@ -142,7 +142,7 @@ func TestStringFIBeneficiaryAdviceVariableLength(t *testing.T) { err = r.parseFIBeneficiaryAdvice() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6410}HLD*******" + line = "{6410}HLD********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiBeneficiaryFI.go b/fiBeneficiaryFI.go index 7ca8fab5..78851bcf 100644 --- a/fiBeneficiaryFI.go +++ b/fiBeneficiaryFI.go @@ -85,7 +85,7 @@ func (fibfi *FIBeneficiaryFI) Parse(record string) error { fibfi.FIToFI.LineSix = value length += read - if len(record) != length { + if !fibfi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiBeneficiaryFI_test.go b/fiBeneficiaryFI_test.go index c15d32b3..8e357ea7 100644 --- a/fiBeneficiaryFI_test.go +++ b/fiBeneficiaryFI_test.go @@ -140,7 +140,7 @@ func TestStringFIBeneficiaryFIVariableLength(t *testing.T) { err = r.parseFIBeneficiaryFI() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6300}*******" + line = "{6300}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiBeneficiary_test.go b/fiBeneficiary_test.go index 3d644b3c..78244f43 100644 --- a/fiBeneficiary_test.go +++ b/fiBeneficiary_test.go @@ -139,7 +139,7 @@ func TestStringFIBeneficiaryVariableLength(t *testing.T) { err = r.parseFIBeneficiary() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6400}*******" + line = "{6400}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiDrawdownDebitAccountAdvice.go b/fiDrawdownDebitAccountAdvice.go index 16244201..c46d9358 100644 --- a/fiDrawdownDebitAccountAdvice.go +++ b/fiDrawdownDebitAccountAdvice.go @@ -86,7 +86,7 @@ func (debitDDAdvice *FIDrawdownDebitAccountAdvice) Parse(record string) error { debitDDAdvice.Advice.LineSix = value length += read - if len(record) != length { + if !debitDDAdvice.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiDrawdownDebitAccountAdvice_test.go b/fiDrawdownDebitAccountAdvice_test.go index 8a80eddf..d05ada0c 100644 --- a/fiDrawdownDebitAccountAdvice_test.go +++ b/fiDrawdownDebitAccountAdvice_test.go @@ -151,7 +151,7 @@ func TestStringFIDrawdownDebitAccountAdviceVariableLength(t *testing.T) { err = r.parseFIDrawdownDebitAccountAdvice() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6110}HLD*******" + line = "{6110}HLD********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiIntermediaryFI.go b/fiIntermediaryFI.go index ba68fb17..46ac96e6 100644 --- a/fiIntermediaryFI.go +++ b/fiIntermediaryFI.go @@ -85,7 +85,7 @@ func (fiifi *FIIntermediaryFI) Parse(record string) error { fiifi.FIToFI.LineSix = value length += read - if len(record) != length { + if !fiifi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiIntermediaryFIAdvice.go b/fiIntermediaryFIAdvice.go index 6625624a..d3093480 100644 --- a/fiIntermediaryFIAdvice.go +++ b/fiIntermediaryFIAdvice.go @@ -86,7 +86,7 @@ func (fiifia *FIIntermediaryFIAdvice) Parse(record string) error { fiifia.Advice.LineSix = value length += read - if len(record) != length { + if !fiifia.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiIntermediaryFIAdvice_test.go b/fiIntermediaryFIAdvice_test.go index 2bc14788..99198414 100644 --- a/fiIntermediaryFIAdvice_test.go +++ b/fiIntermediaryFIAdvice_test.go @@ -150,7 +150,7 @@ func TestStringFIIntermediaryFIAdviceVariableLength(t *testing.T) { err = r.parseFIIntermediaryFIAdvice() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6210}HLD*******" + line = "{6210}HLD********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiIntermediaryFI_test.go b/fiIntermediaryFI_test.go index 1fd23eee..80be2905 100644 --- a/fiIntermediaryFI_test.go +++ b/fiIntermediaryFI_test.go @@ -139,7 +139,7 @@ func TestStringFIIntermediaryFIVariableLength(t *testing.T) { err = r.parseFIIntermediaryFI() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6200}*******" + line = "{6200}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiPaymentMethodToBeneficiary.go b/fiPaymentMethodToBeneficiary.go index d20c2067..ffb3c085 100644 --- a/fiPaymentMethodToBeneficiary.go +++ b/fiPaymentMethodToBeneficiary.go @@ -54,7 +54,7 @@ func (pm *FIPaymentMethodToBeneficiary) Parse(record string) error { pm.AdditionalInformation = value length += read - if len(record) != length { + if !pm.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiPaymentMethodToBeneficiary_test.go b/fiPaymentMethodToBeneficiary_test.go index 254664d2..57f81dbf 100644 --- a/fiPaymentMethodToBeneficiary_test.go +++ b/fiPaymentMethodToBeneficiary_test.go @@ -95,7 +95,7 @@ func TestStringFIPaymentMethodToBeneficiaryVariableLength(t *testing.T) { err = r.parseFIPaymentMethodToBeneficiary() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6420}CHECK**" + line = "{6420}CHECK***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/fiReceiverFI.go b/fiReceiverFI.go index b0b13c14..346bb3b4 100644 --- a/fiReceiverFI.go +++ b/fiReceiverFI.go @@ -85,7 +85,7 @@ func (firfi *FIReceiverFI) Parse(record string) error { firfi.FIToFI.LineSix = value length += read - if len(record) != length { + if !firfi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/fiReceiverFI_test.go b/fiReceiverFI_test.go index 568362b8..6320d5e4 100644 --- a/fiReceiverFI_test.go +++ b/fiReceiverFI_test.go @@ -139,7 +139,7 @@ func TestStringFIReceiverFIVariableLength(t *testing.T) { err = r.parseFIReceiverFI() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{6100}*******" + line = "{6100}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/grossAmountRemittanceDocument.go b/grossAmountRemittanceDocument.go index 36f8f30a..81445174 100644 --- a/grossAmountRemittanceDocument.go +++ b/grossAmountRemittanceDocument.go @@ -57,7 +57,7 @@ func (gard *GrossAmountRemittanceDocument) Parse(record string) error { gard.RemittanceAmount.Amount = value length += read - if len(record) != length { + if !gard.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/grossAmountRemittanceDocument_test.go b/grossAmountRemittanceDocument_test.go index 4b7f17bf..e13d6fdb 100644 --- a/grossAmountRemittanceDocument_test.go +++ b/grossAmountRemittanceDocument_test.go @@ -106,7 +106,7 @@ func TestStringGrossAmountRemittanceDocumentVariableLength(t *testing.T) { err = r.parseGrossAmountRemittanceDocument() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{8500}USD1234.56**" + line = "{8500}USD1234.56***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/institutionAccount.go b/institutionAccount.go index 8be06ad8..abac2d05 100644 --- a/institutionAccount.go +++ b/institutionAccount.go @@ -85,7 +85,7 @@ func (iAccount *InstitutionAccount) Parse(record string) error { iAccount.CoverPayment.SwiftLineFive = value length += read - if len(record) != length { + if !iAccount.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/institutionAccount_test.go b/institutionAccount_test.go index 842470b6..d4297296 100644 --- a/institutionAccount_test.go +++ b/institutionAccount_test.go @@ -146,7 +146,7 @@ func TestStringInstitutionAccountVariableLength(t *testing.T) { err = r.parseInstitutionAccount() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{7057}*******" + line = "{7057}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/instructedAmount.go b/instructedAmount.go index ab13396b..a9d4ebd5 100644 --- a/instructedAmount.go +++ b/instructedAmount.go @@ -60,7 +60,7 @@ func (ia *InstructedAmount) Parse(record string) error { ia.Amount = value length += read - if len(record) != length { + if !ia.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/instructedAmount_test.go b/instructedAmount_test.go index b5758342..abb0ebfa 100644 --- a/instructedAmount_test.go +++ b/instructedAmount_test.go @@ -112,7 +112,7 @@ func TestStringInstructedAmountVariableLength(t *testing.T) { err = r.parseInstructedAmount() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{3710}USD4567,89**" + line = "{3710}USD4567,89***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/instructingFI.go b/instructingFI.go index 37d9579c..f085a664 100644 --- a/instructingFI.go +++ b/instructingFI.go @@ -79,7 +79,7 @@ func (ifi *InstructingFI) Parse(record string) error { ifi.FinancialInstitution.Address.AddressLineThree = value length += read - if len(record) != length { + if !ifi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/intermediaryInstitution.go b/intermediaryInstitution.go index fc5cad86..11f233da 100644 --- a/intermediaryInstitution.go +++ b/intermediaryInstitution.go @@ -85,7 +85,7 @@ func (ii *IntermediaryInstitution) Parse(record string) error { ii.CoverPayment.SwiftLineFive = value length += read - if len(record) != length { + if !ii.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/localInstrument.go b/localInstrument.go index eee40dcb..1dbdcc58 100644 --- a/localInstrument.go +++ b/localInstrument.go @@ -59,7 +59,7 @@ func (li *LocalInstrument) Parse(record string) error { li.ProprietaryCode = value length += read - if len(record) != length { + if !li.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/messageDisposition.go b/messageDisposition.go index 03fb37cb..1a63f3dc 100644 --- a/messageDisposition.go +++ b/messageDisposition.go @@ -80,7 +80,7 @@ func (md *MessageDisposition) Parse(record string) error { md.MessageStatusIndicator = value length += read - if len(record) != length { + if !md.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/messageDisposition_test.go b/messageDisposition_test.go index 2bf2587d..2d7ce7d3 100644 --- a/messageDisposition_test.go +++ b/messageDisposition_test.go @@ -75,7 +75,7 @@ func TestStringMessageDispositionVariableLength(t *testing.T) { err = r.parseMessageDisposition() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{1100}*****" + line = "{1100}*******" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/orderingCustomer.go b/orderingCustomer.go index 1c5d5813..fffe91e9 100644 --- a/orderingCustomer.go +++ b/orderingCustomer.go @@ -85,7 +85,7 @@ func (oc *OrderingCustomer) Parse(record string) error { oc.CoverPayment.SwiftLineFive = value length += read - if len(record) != length { + if !oc.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/orderingCustomer_test.go b/orderingCustomer_test.go index f622279a..d2ed534a 100644 --- a/orderingCustomer_test.go +++ b/orderingCustomer_test.go @@ -146,7 +146,7 @@ func TestStringOrderingCustomerVariableLength(t *testing.T) { err = r.parseOrderingCustomer() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{7050}*******" + line = "{7050}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/orderingInstitution.go b/orderingInstitution.go index f95247c9..b26a89cd 100644 --- a/orderingInstitution.go +++ b/orderingInstitution.go @@ -85,7 +85,7 @@ func (oi *OrderingInstitution) Parse(record string) error { oi.CoverPayment.SwiftLineFive = value length += read - if len(record) != length { + if !oi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/orderingInstitution_test.go b/orderingInstitution_test.go index a650abc3..d3dbb6e2 100644 --- a/orderingInstitution_test.go +++ b/orderingInstitution_test.go @@ -145,7 +145,7 @@ func TestStringOrderingInstitutionVariableLength(t *testing.T) { err = r.parseOrderingInstitution() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{7052}*******" + line = "{7052}********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/originator.go b/originator.go index 6ebcd86b..d080c9ba 100644 --- a/originator.go +++ b/originator.go @@ -79,7 +79,7 @@ func (o *Originator) Parse(record string) error { o.Personal.Address.AddressLineThree = value length += read - if len(record) != length { + if !o.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/originatorFI.go b/originatorFI.go index ee83785e..0362e2e4 100644 --- a/originatorFI.go +++ b/originatorFI.go @@ -85,7 +85,7 @@ func (ofi *OriginatorFI) Parse(record string) error { ofi.FinancialInstitution.Address.AddressLineThree = value length += read - if len(record) != length { + if !ofi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/originatorOptionF.go b/originatorOptionF.go index aff29214..eb4d6e27 100644 --- a/originatorOptionF.go +++ b/originatorOptionF.go @@ -142,7 +142,7 @@ func (oof *OriginatorOptionF) Parse(record string) error { oof.LineThree = value length += read - if len(record) != length { + if !oof.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/originatorToBeneficiary.go b/originatorToBeneficiary.go index 517fd6d3..b468abfd 100644 --- a/originatorToBeneficiary.go +++ b/originatorToBeneficiary.go @@ -77,7 +77,7 @@ func (ob *OriginatorToBeneficiary) Parse(record string) error { ob.LineFour = value length += read - if len(record) != length { + if !ob.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/outputMessageAccountabilityData.go b/outputMessageAccountabilityData.go index 484ca2d2..4a4438e4 100644 --- a/outputMessageAccountabilityData.go +++ b/outputMessageAccountabilityData.go @@ -95,7 +95,7 @@ func (omad *OutputMessageAccountabilityData) Parse(record string) error { omad.OutputFRBApplicationIdentification = value length += read - if len(record) != length { + if !omad.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/paymentNotification.go b/paymentNotification.go index cc60dcf3..3ae81d15 100644 --- a/paymentNotification.go +++ b/paymentNotification.go @@ -106,7 +106,7 @@ func (pn *PaymentNotification) Parse(record string) error { pn.EndToEndIdentification = value length += read - if len(record) != length { + if !pn.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/paymentNotification_test.go b/paymentNotification_test.go index ec86f012..d2ddd117 100644 --- a/paymentNotification_test.go +++ b/paymentNotification_test.go @@ -147,7 +147,7 @@ func TestStringPaymentNotificationVariableLength(t *testing.T) { err = r.parsePaymentNotification() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{3620}********" + line = "{3620}*********" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/previousMessageIdentifier.go b/previousMessageIdentifier.go index ded20e2a..dc38f31a 100644 --- a/previousMessageIdentifier.go +++ b/previousMessageIdentifier.go @@ -50,7 +50,7 @@ func (pmi *PreviousMessageIdentifier) Parse(record string) error { pmi.PreviousMessageIdentifier = value length += read - if len(record) != length { + if !pmi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/primaryRemittanceDocument.go b/primaryRemittanceDocument.go index cd1b3951..37df57b3 100644 --- a/primaryRemittanceDocument.go +++ b/primaryRemittanceDocument.go @@ -71,7 +71,7 @@ func (prd *PrimaryRemittanceDocument) Parse(record string) error { prd.Issuer = value length += read - if len(record) != length { + if !prd.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/reader.go b/reader.go index b66b17f3..8a5c3f8c 100644 --- a/reader.go +++ b/reader.go @@ -32,8 +32,14 @@ type Reader struct { tagName string // errors holds each error encountered when attempting to parse the file errors base.ErrorList + // headerData holds header static data for file + headerData string } +var ( + tagRegex = regexp.MustCompile(`{([0-9]{4})}`) +) + // error returns a new ParseError based on err func (r *Reader) parseError(err error) error { if err == nil { @@ -71,15 +77,33 @@ func NewReader(r io.Reader) *Reader { // the appropriate error if issues are found. func (r *Reader) Read() (File, error) { + spiltString := func(line string) []string { + + // strip new lines + line = strings.ReplaceAll(strings.ReplaceAll(line, "\r\n", ""), "\n", "") + + // split line by tag again + indexes := tagRegex.FindAllStringIndex(line, -1) + var result []string + last := len(line) + for i := range indexes { + index := indexes[len(indexes)-1-i][0] + result = append([]string{line[index:last]}, result...) + last = index + } + return result + } + r.lineNum = 0 // read through the entire file for r.scanner.Scan() { line := r.scanner.Text() - r.lineNum++ - // ToDo: File length Check? - r.line = strings.TrimRight(line, "\r\n") - if err := r.parseLine(); err != nil { - r.errors.Add(err) + for _, subLine := range spiltString(line) { + r.lineNum++ + r.line = subLine + if err := r.parseLine(); err != nil { + r.errors.Add(err) + } } } @@ -173,7 +197,6 @@ func (r *Reader) parseLine() error { //nolint:gocyclo if err := r.parseExchangeRate(); err != nil { return err } - case TagBeneficiaryIntermediaryFI: if err := r.parseBeneficiaryIntermediaryFI(); err != nil { return err @@ -343,6 +366,10 @@ func (r *Reader) parseLine() error { //nolint:gocyclo return err } default: + if r.lineNum == 1 && !tagRegex.MatchString(r.line[:6]) { + r.headerData = r.line + return nil + } return NewErrInvalidTag(r.line[:6]) } return nil @@ -1128,10 +1155,6 @@ func (r *Reader) parseErrorWire() error { return nil } -var ( - tagRegex = regexp.MustCompile(`{([0-9]{4})}`) -) - //scanLinesWithSegmentFormat allows Reader to read each segment func scanLinesWithSegmentFormat(data []byte, atEOF bool) (advance int, token []byte, err error) { diff --git a/receiptTimeStamp.go b/receiptTimeStamp.go index c4b42e8b..ffd47278 100644 --- a/receiptTimeStamp.go +++ b/receiptTimeStamp.go @@ -68,7 +68,7 @@ func (rts *ReceiptTimeStamp) Parse(record string) error { rts.ReceiptApplicationIdentification = value length += read - if len(record) != length { + if !rts.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/receiverDepositoryInstitution.go b/receiverDepositoryInstitution.go index af53cb24..32cdce39 100644 --- a/receiverDepositoryInstitution.go +++ b/receiverDepositoryInstitution.go @@ -59,7 +59,7 @@ func (rdi *ReceiverDepositoryInstitution) Parse(record string) error { rdi.ReceiverShortName = value length += read - if len(record) != length { + if !rdi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/relatedRemittance.go b/relatedRemittance.go index 29861ee2..10adb083 100644 --- a/relatedRemittance.go +++ b/relatedRemittance.go @@ -189,7 +189,7 @@ func (rr *RelatedRemittance) Parse(record string) error { rr.RemittanceData.AddressLineSeven = value length += read - if len(record) != length { + if !rr.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/remittance.go b/remittance.go index 85a22e2a..6a16233f 100644 --- a/remittance.go +++ b/remittance.go @@ -78,7 +78,7 @@ func (ri *Remittance) Parse(record string) error { ri.CoverPayment.SwiftLineFour = value length += read - if len(record) != length { + if !ri.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/remittanceBeneficiary.go b/remittanceBeneficiary.go index 525003a7..2f0b75cd 100644 --- a/remittanceBeneficiary.go +++ b/remittanceBeneficiary.go @@ -212,7 +212,7 @@ func (rb *RemittanceBeneficiary) Parse(record string) error { rb.RemittanceData.CountryOfResidence = value length += read - if len(record) != length { + if !rb.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/remittanceFreeText.go b/remittanceFreeText.go index f6b0f2e1..6310d8fb 100644 --- a/remittanceFreeText.go +++ b/remittanceFreeText.go @@ -68,7 +68,7 @@ func (rft *RemittanceFreeText) Parse(record string) error { rft.LineThree = value length += read - if len(record) != length { + if !rft.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/remittanceOriginator.go b/remittanceOriginator.go index 1af87081..9f521d81 100644 --- a/remittanceOriginator.go +++ b/remittanceOriginator.go @@ -266,7 +266,7 @@ func (ro *RemittanceOriginator) Parse(record string) error { ro.ContactOther = value length += read - if len(record) != length { + if !ro.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/secondaryRemittanceDocument.go b/secondaryRemittanceDocument.go index 4f2b91c4..a8c73012 100644 --- a/secondaryRemittanceDocument.go +++ b/secondaryRemittanceDocument.go @@ -77,7 +77,7 @@ func (srd *SecondaryRemittanceDocument) Parse(record string) error { srd.Issuer = value length += read - if len(record) != length { + if !srd.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/senderDepositoryInstitution.go b/senderDepositoryInstitution.go index e495df4c..5a0b87ca 100644 --- a/senderDepositoryInstitution.go +++ b/senderDepositoryInstitution.go @@ -59,7 +59,7 @@ func (sdi *SenderDepositoryInstitution) Parse(record string) error { sdi.SenderShortName = value length += read - if len(record) != length { + if !sdi.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/senderDepositoryInstitution_test.go b/senderDepositoryInstitution_test.go index e1718305..2565dea8 100644 --- a/senderDepositoryInstitution_test.go +++ b/senderDepositoryInstitution_test.go @@ -115,7 +115,7 @@ func TestStringSenderDepositoryInstitutionVariableLength(t *testing.T) { err = r.parseSenderDepositoryInstitution() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{3100}1*A**" + line = "{3100}1*A***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/senderReference.go b/senderReference.go index 866da008..06e342bf 100644 --- a/senderReference.go +++ b/senderReference.go @@ -50,7 +50,7 @@ func (sr *SenderReference) Parse(record string) error { sr.SenderReference = value length += read - if len(record) != length { + if !sr.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/senderReference_test.go b/senderReference_test.go index 4716b4e7..1449c4d4 100644 --- a/senderReference_test.go +++ b/senderReference_test.go @@ -81,7 +81,7 @@ func TestStringSenderReferenceVariableLength(t *testing.T) { err = r.parseSenderReference() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{3320}**" + line = "{3320}***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/senderSupplied.go b/senderSupplied.go index ea69b478..51d1769e 100644 --- a/senderSupplied.go +++ b/senderSupplied.go @@ -76,7 +76,7 @@ func (ss *SenderSupplied) Parse(record string) error { ss.MessageDuplicationCode = ss.parseStringField(ss.MessageDuplicationCode) - if len(record) != length { + if !ss.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/senderSupplied_test.go b/senderSupplied_test.go index 0392fe10..d67325ee 100644 --- a/senderSupplied_test.go +++ b/senderSupplied_test.go @@ -129,7 +129,7 @@ func TestStringSenderSuppliedVariableLength(t *testing.T) { err = r.parseSenderSupplied() require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error()) - line = "{1500}301*T**" + line = "{1500}301*T***" r = NewReader(strings.NewReader(line)) r.line = line diff --git a/senderToReceiver.go b/senderToReceiver.go index 87e733f5..2712c498 100644 --- a/senderToReceiver.go +++ b/senderToReceiver.go @@ -92,7 +92,7 @@ func (str *SenderToReceiver) Parse(record string) error { str.CoverPayment.SwiftLineSix = value length += read - if len(record) != length { + if !str.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() } diff --git a/serviceMessage.go b/serviceMessage.go index 7a5970d9..69b83eeb 100644 --- a/serviceMessage.go +++ b/serviceMessage.go @@ -149,7 +149,7 @@ func (sm *ServiceMessage) Parse(record string) error { sm.LineTwelve = value length += read - if len(record) != length { + if !sm.verifyDataWithReadLength(record, length) { return NewTagMaxLengthErr() }