Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

strip non ascii characters in fields since banks won't handle them #16

Merged
merged 1 commit into from

2 participants

@barmstrong

For example a customer name with special chars would make it through to the nacha file and the bank can't handle it.

I've only tested this in 1.9.

@jm81 jm81 merged commit 90a22c9 into jm81:master
@jm81
Owner

I added support for 1.8 using Iconv (92dff91). I'm not sure if this is the best way, but it keeps 1.8 from breaking. I also moved the stringify call down to make sure the right number of spaces are added after characters are removed.

@barmstrong

Awesome - nice fix also on the length fix! (and 1.8 support) cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 17, 2013
This page is out of date. Refresh to see the latest.
View
6 examples/ach/batch_example.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'example_helper'
describe ACH::Batch do
@@ -119,5 +120,10 @@ def new_batch
@credit.individual_name = "Employee Name That Is Much Too Long"
@credit.individual_name_to_ach.should == "Employee Name That Is "
end
+
+ it 'should strip non ascii characters' do
+ @credit.individual_name = "Jacob Møller"
+ @credit.individual_name_to_ach.should == "Jacob Mller "
+ end
end
end
View
2  lib/ach.rb
@@ -36,6 +36,6 @@ module ACH
# Include Records module to simplify accessing Records classes.
module ACH
- VERSION = '0.4.2'
+ VERSION = '0.4.3'
include Records
end
View
17 lib/ach/field_identifiers.rb
@@ -1,5 +1,14 @@
module ACH
module FieldIdentifiers
+
+ # these are used to convert non ascii characters to UTF-8
+
+ ENCODING_OPTIONS = {
+ :invalid => :replace, # Replace invalid byte sequences
+ :undef => :replace, # Replace anything not defined in ASCII
+ :replace => '', # Use a blank for those replacements
+ }
+
# NOTE: the msg parameter is unused and should be removed when the API can change
def field(name, klass, stringify = nil, default = nil, validate = nil, msg ='')
fields << name
@@ -38,11 +47,11 @@ def field(name, klass, stringify = nil, default = nil, validate = nil, msg ='')
end
end
- if stringify.nil?
- return val
- else
- stringify.call(val)
+ if !stringify.nil?
+ val = stringify.call(val)
end
+
+ val.encode Encoding.find('ASCII'), ENCODING_OPTIONS
end
end
View
2  lib/ach/version.rb
@@ -1,3 +1,3 @@
module ACH
- VERSION = '0.4.2'.freeze
+ VERSION = '0.4.3'.freeze
end
Something went wrong with that request. Please try again.