Skip to content

Commit

Permalink
Make it less likely that colons right after newlines break the parser (
Browse files Browse the repository at this point in the history
…#31)

Co-authored-by: Marvin Killing <[email protected]>

* add failing test case for #30
* Make statement parsing work when there are colons right after newlines. Fixes #30 
* simplify parsing mechanism

fixes #30
  • Loading branch information
mkilling authored and Uepsilon committed Jun 3, 2019
1 parent 2c145a5 commit 19a5e44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/cmxl/statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ def transactions
def parse!
self.fields = []

# split transactions, each transaction starts with a colon after a linebreak
# do not remove line breaks within transaction lines as they are used to determine field details
# e.g. :61:-supplementary
source.split("\n:").each(&:strip!).each do |line|
line = ":#{line}" unless line =~ /^:/ # prepend lost : via split
lines = source.split(/(:[0-9A-Z]{2,3}:)/m).reject(&:empty?).each_slice(2).map(&:join)

lines.map do |line|
if line =~ /\A:86:/
if field = fields.last
field.add_meta_data(line)
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/mt940-with-colon-after-line-break.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:20:131110
:25:45050050/76198810
:28:27/01
:60F:C131016DEM84349,74
:61:131017D6800,NCHK16703074
/OCMT/CAD47,11
:86:106?109075/658?20EREF+000000000193592204?21MREF+CN3R3U?22CRED+DE7
600200000132558?23SVWZ+STARTER//8449273399/US?24 22-04-2019T03:46
:08 Karten?25nr. 5355999999999975 Origi?26nal 49,00 USD 1 EUR/1,
12385?27 USD Entgelt 0,44 EUR?30DEUTDEDBFRA?31DE1950070024000402
0480?32DEUTSCHE BANK
8 changes: 8 additions & 0 deletions spec/statement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@
expect(subject.bic).to eq('10020030')
end
end

describe 'statement with colon right after linebreak' do
subject { Cmxl.parse(mt940_file('mt940-with-colon-after-line-break')).first.transactions.first }

it 'has the right details' do
expect(subject.to_h['details']).to eq('?109075/658?20EREF+000000000193592204?21MREF+CN3R3U?22CRED+DE7600200000132558?23SVWZ+STARTER//8449273399/US?24 22-04-2019T03:46:08 Karten?25nr. 5355999999999975 Origi?26nal 49,00 USD 1 EUR/1,12385?27 USD Entgelt 0,44 EUR?30DEUTDEDBFRA?31DE19500700240004020480?32DEUTSCHE BANK')
end
end
end

context 'mt942' do
Expand Down

0 comments on commit 19a5e44

Please sign in to comment.