Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend allowed characters' set #93

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactoring: Move allowed characters out of hardcoded regex
This refactoring will allow for an easier addition/deletion of allowed
characters, without directly manipulating the regular expression.
kiriakosv committed Mar 13, 2021
commit bdd9ee6a0b2943d035f710b12751715df9ca3cc4
1 change: 1 addition & 0 deletions lib/misc/allowed_chars.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ÄÖÜäöüß&*$% ':?,-(+.)/
4 changes: 3 additions & 1 deletion lib/sepa_king/converter.rb
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ def convert(*attributes, options)
end

module InstanceMethods
ALLOWED_CHARS = Regexp.escape(File.read('lib/misc/allowed_chars.txt')).freeze

def convert_text(value)
return unless value

@@ -29,7 +31,7 @@ def convert_text(value)
gsub(/\n+/,' ').

# Remove all invalid characters
gsub(/[^a-zA-Z0-9ÄÖÜäöüß&*$%\ \'\:\?\,\-\(\+\.\)\/]/, '').
gsub(/[^#{ALLOWED_CHARS}]/, '').

# Remove leading and trailing spaces
strip