Modifies the tag sanitizer to truncate tags longer than 40
I could not make a nice ActAsTaggable error message, this is way faster
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
class TagSanitizer
|
||||
TAG_MAX_LENGTH = 40
|
||||
|
||||
DISALLOWED_STRINGS = %w(? < > = /)
|
||||
|
||||
@@ -7,7 +8,7 @@ class TagSanitizer
|
||||
DISALLOWED_STRINGS.each do |s|
|
||||
tag.gsub!(s, '')
|
||||
end
|
||||
tag
|
||||
tag.truncate(TAG_MAX_LENGTH)
|
||||
end
|
||||
|
||||
def sanitize_tag_list(tag_list)
|
||||
|
||||
@@ -12,6 +12,12 @@ describe TagSanitizer do
|
||||
it 'filters out dangerous strings' do
|
||||
expect(subject.sanitize_tag('user_id=1')).to eq('user_id1')
|
||||
end
|
||||
|
||||
it 'sets up a max length for each tag' do
|
||||
long_tag = '1' * (TagSanitizer::TAG_MAX_LENGTH + 100)
|
||||
|
||||
expect(subject.sanitize_tag(long_tag).size).to eq(TagSanitizer::TAG_MAX_LENGTH)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sanitize_tag_list' do
|
||||
|
||||
Reference in New Issue
Block a user