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:
kikito
2015-09-09 18:30:27 +02:00
parent 0e96c82faa
commit c750765bca
2 changed files with 8 additions and 1 deletions

View File

@@ -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)

View File

@@ -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