Skip to content

Map text according to EPC SEPA conversion table#105

Open
kiriakosv wants to merge 2 commits into
salesking:masterfrom
kiriakosv:epc-conversion-table
Open

Map text according to EPC SEPA conversion table#105
kiriakosv wants to merge 2 commits into
salesking:masterfrom
kiriakosv:epc-conversion-table

Conversation

@kiriakosv

Copy link
Copy Markdown

Instead of whitelisting certain characters, we map according to EPC SEPA conversion guidelines.

Resolves #92

Comment thread lib/sepa_king/converter.rb Outdated
Comment thread spec/converter_spec.rb Outdated
@olleolleolle

Copy link
Copy Markdown
Contributor

I think this is stunning in its clarity, following the Best Practices outlined by the EPC.

@ledermann

ledermann commented Jun 8, 2022

Copy link
Copy Markdown
Member

Hey guys, thanks for your great work!
To minimize modifications in the existing specs, I suggest adding the following changes:

diff --git a/lib/sepa_king/converter.rb b/lib/sepa_king/converter.rb
index ead034f..9dbea7e 100644
--- a/lib/sepa_king/converter.rb
+++ b/lib/sepa_king/converter.rb
@@ -23,7 +23,7 @@ module InstanceMethods
       private_constant :EPC_MAPPING

       def convert_text(value)
-        return unless value
+        return value unless value.present?

         # Map chars according to:
         # http://www.europeanpaymentscouncil.eu/index.cfm/knowledge-bank/epc-documents/sepa-requirements-for-an-extended-character-set-unicode-subset-best-practices/
diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb
index 6f0521a..0219fa3 100644
--- a/spec/converter_spec.rb
+++ b/spec/converter_spec.rb
@@ -26,6 +26,10 @@ it 'should convert number' do
       expect(convert_text(1234)).to eq('1234')
     end

+    it 'should not touch valid chars' do
+      expect(convert_text("abc-ABC-0123- :?,-(+.)/")).to eq("abc-ABC-0123- :?,-(+.)/")
+    end
+
     it 'should not touch nil' do
       expect(convert_text(nil)).to eq(nil)
     end
diff --git a/spec/transaction_spec.rb b/spec/transaction_spec.rb
index d7f8d01..30f5730 100644
--- a/spec/transaction_spec.rb
+++ b/spec/transaction_spec.rb
@@ -68,7 +68,7 @@ it 'should accept valid value' do
     end

     it 'should not accept invalid value' do
-      expect(SEPA::Transaction).not_to accept('', for: :name)
+      expect(SEPA::Transaction).not_to accept('', {}, for: :name)
     end
   end

What do you think?

@kiriakosv

kiriakosv commented Jun 8, 2022

Copy link
Copy Markdown
Author

Hey guys, thanks for your great work! To minimize modifications in the existing specs, I suggest adding the following changes:

diff --git a/lib/sepa_king/converter.rb b/lib/sepa_king/converter.rb
index ead034f..9dbea7e 100644
--- a/lib/sepa_king/converter.rb
+++ b/lib/sepa_king/converter.rb
@@ -23,7 +23,7 @@ module InstanceMethods
       private_constant :EPC_MAPPING

       def convert_text(value)
-        return unless value
+        return value unless value.present?

         # Map chars according to:
         # http://www.europeanpaymentscouncil.eu/index.cfm/knowledge-bank/epc-documents/sepa-requirements-for-an-extended-character-set-unicode-subset-best-practices/
diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb
index 6f0521a..0219fa3 100644
--- a/spec/converter_spec.rb
+++ b/spec/converter_spec.rb
@@ -26,6 +26,10 @@ it 'should convert number' do
       expect(convert_text(1234)).to eq('1234')
     end

+    it 'should not touch valid chars' do
+      expect(convert_text("abc-ABC-0123- :?,-(+.)/")).to eq("abc-ABC-0123- :?,-(+.)/")
+    end
+
     it 'should not touch nil' do
       expect(convert_text(nil)).to eq(nil)
     end
diff --git a/spec/transaction_spec.rb b/spec/transaction_spec.rb
index d7f8d01..30f5730 100644
--- a/spec/transaction_spec.rb
+++ b/spec/transaction_spec.rb
@@ -68,7 +68,7 @@ it 'should accept valid value' do
     end

     it 'should not accept invalid value' do
-      expect(SEPA::Transaction).not_to accept('', for: :name)
+      expect(SEPA::Transaction).not_to accept('', {}, for: :name)
     end
   end

What do you think?

This is about the desired behaviour. Do we want to convert an empty hash to '()', as it currently does in this PR, or keep the previous behaviour (validation error)? I think I agree with you, we should revert back to the previous behaviour.

Also, something else; am I correct to assume that this block belongs to the Name context? If so, I could add the empty hash case here and remove the misplaced block.

@ledermann

Copy link
Copy Markdown
Member

Also, something else; am I correct to assume that this block belongs to the Name context? If so, I could add the empty hash case here and remove the misplaced block.

Yes, seems reasonable.

@kiriakosv kiriakosv force-pushed the epc-conversion-table branch from 59d1150 to 6082f4b Compare June 13, 2022 18:48
Comment thread lib/sepa_king/converter.rb
@fpietka

fpietka commented Aug 3, 2022

Copy link
Copy Markdown

I was wondering: in the official conversion table they suggest both a "basic" and a "long term" replacement. Won't there be any issue introducing html entities (containing & character) if, maybe, the bank isn't ready to process this character at all?

It may be a non issue as I haven't tested it myself, but I thought it would we worth talking about.
What do you think?

@fpietka

fpietka commented Aug 3, 2022

Copy link
Copy Markdown

We tested with & transformed to & and it wasn't valid with our bank. Which led me to think we would probably need to be able to do the basic conversion if needed.

@olleolleolle

Copy link
Copy Markdown
Contributor

Would it be interesting to be able to supply one's own set of replacements?

@fpietka

fpietka commented Aug 5, 2022

Copy link
Copy Markdown

@olleolleolle I'm divided about this, as I would rather not handle SEPA conversion in my own project 🤔.

FYI I was referring at the conversion table in which I think we can understand that basic character set often means removing them (which seems to be my case):
image

@kiriakosv

kiriakosv commented Aug 10, 2022

Copy link
Copy Markdown
Author

Hello, for special characters I followed chapter 6.2 here.

For the & case, the corresponding mapping is +. The only possibly problematic mappings are:

  • < to &lt
  • > to &gt
  • ' to &apos
  • "" to &quot

Two possible solutions that come to mind are:

  1. Replace these chars with an empty char (remove them)
  2. Raise error if at least one of this chars is present

What do you think?

@fpietka

fpietka commented Sep 2, 2022

Copy link
Copy Markdown

@kiriakosv what we're doing in the meantime is removing those chars.
Having an error would mean each user of the library would have to handle those themselves, which IMHO would not be desirable. Not sure having the option to be able catch an exception would bring much value, but I might be mistaken.

@kiriakosv

Copy link
Copy Markdown
Author

@kiriakosv what we're doing in the meantime is removing those chars.
Having an error would mean each user of the library would have to handle those themselves, which IMHO would not be desirable. Not sure having the option to be able catch an exception would bring much value, but I might be mistaken.

I too prefer removing these chars. If everyone is OK we can proceed like this.

@zangab

zangab commented Nov 3, 2025

Copy link
Copy Markdown

what is the status here? is there an update on this?

@kiriakosv

Copy link
Copy Markdown
Author

what is the status here? is there an update on this?

I think that if any core maintainer agrees we can proceed per:

@kiriakosv what we're doing in the meantime is removing those chars.
Having an error would mean each user of the library would have to handle those themselves, which IMHO would not be desirable. Not sure having the option to be able catch an exception would bring much value, but I might be mistaken.

I too prefer removing these chars. If everyone is OK we can proceed like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend allowed characters in InstanceMethods.convert_text

5 participants