Purify Categories

Apply the same methodology, as in Revision 432,
to the category chunk-handler. This completes
the replacement of all the code that looks like

  if string.is_utf8?
    do something
  else
    complain
  end

with code that looks like

  string.purify
  do something
This commit is contained in:
Jacques Distler 2009-09-07 20:38:09 -05:00
parent c79fef9c01
commit 116255dc0d
3 changed files with 14 additions and 2 deletions

View file

@ -18,7 +18,8 @@ class Category < Chunk::Abstract
def initialize(match_data, content) def initialize(match_data, content)
super(match_data, content) super(match_data, content)
@hidden = match_data[1] @hidden = match_data[1]
@list = match_data[2].split(',').map { |c| c.to_s.is_utf8? ? c.strip.escapeHTML : nil } # @list = match_data[2].split(',').map { |c| clean = c.purify; clean.strip.escapeHTML if clean }
@list = match_data[2].split(',').map { |c| clean = c.purify.strip.escapeHTML; clean if clean != ''}
@list.compact! @list.compact!
@unmask_text = '' @unmask_text = ''
if @hidden if @hidden

View file

@ -31,7 +31,7 @@ class String
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)+\Z/nx; )*\Z/nx;
#++ #++
# Check whether a string is valid utf-8 # Check whether a string is valid utf-8

View file

@ -12,6 +12,12 @@ class CategoryTest < Test::Unit::TestCase
match(Category, ':category: test', :list => ['test'], :hidden => ':') match(Category, ':category: test', :list => ['test'], :hidden => ':')
end end
def test_no_category
match(Category, 'category: ', :list => [], :hidden => nil)
match(Category, 'category : chunk test , ', :list => ['chunk test'], :hidden => nil)
match(Category, ':category:', :list => [], :hidden => ':')
end
def test_multiple_categories def test_multiple_categories
match(Category, 'category: test, multiple', :list => ['test', 'multiple'], :hidden => nil) match(Category, 'category: test, multiple', :list => ['test', 'multiple'], :hidden => nil)
match(Category, 'category : chunk test , multi category,regression test case ', match(Category, 'category : chunk test , multi category,regression test case ',
@ -26,4 +32,9 @@ class CategoryTest < Test::Unit::TestCase
) )
end end
def test_multiple_categories_invalid_utf8
match(Category, "category: test, multiple,\000egg", :list => ['test', 'multiple', 'egg'], :hidden => nil)
match(Category, "category : chunk test , multi category,,e\000gg", :list => ['chunk test', 'multi category', 'egg'], :hidden => nil)
end
end end