Changeset 2265
- Timestamp:
- 09/19/05 21:36:36 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/text_helper.rb (modified) (1 diff)
- trunk/actionpack/test/template/text_helper_test.rb (modified) (3 diffs)
- trunk/actionpack/test/testing_sandbox.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r2257 r2265 1 1 *SVN* 2 3 * Make the truncate() helper multi-byte safe (assuming $KCODE has been set to something other than "NONE") #2103 2 4 3 5 * Add routing tests from #1945 [ben@groovie.org] trunk/actionpack/lib/action_view/helpers/text_helper.rb
r2241 r2265 21 21 def truncate(text, length = 30, truncate_string = "...") 22 22 if text.nil? then return end 23 if text.length > length then text[0..(length - 3)] + truncate_string else text end 23 24 if $KCODE == "NONE" 25 text.length > length ? text[0..(length - 3)] + truncate_string : text 26 else 27 chars = text.split(//) 28 chars.length > length ? chars[0..(length-3)].join + truncate_string : text 29 end 24 30 end 25 31 trunk/actionpack/test/template/text_helper_test.rb
r2241 r2265 1 1 require 'test/unit' 2 require "#{File.dirname(__FILE__)}/../testing_sandbox" 2 3 require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper' 3 4 require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/numeric' # for human_size … … 8 9 include ActionView::Helpers::TextHelper 9 10 include ActionView::Helpers::TagHelper 11 include TestingSandbox 10 12 11 13 def setup … … 24 26 assert_equal "Hello World!", truncate("Hello World!", 12) 25 27 assert_equal "Hello Worl...", truncate("Hello World!!", 12) 28 end 29 30 def test_truncate_multibyte_without_kcode 31 result = execute_in_sandbox(<<-'CODE') 32 require "#{File.dirname(__FILE__)}/../lib/action_view/helpers/text_helper" 33 include ActionView::Helpers::TextHelper 34 truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10) 35 CODE 36 37 assert_equal "\354\225\210\353\205\225\355\225...", result 38 end 39 40 def test_truncate_multibyte_with_kcode 41 result = execute_in_sandbox(<<-'CODE') 42 $KCODE = "u" 43 require 'jcode' 44 45 require "#{File.dirname(__FILE__)}/../lib/action_view/helpers/text_helper" 46 include ActionView::Helpers::TextHelper 47 truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254\353\236 \354\225\204\353\235\274\353\246\254\354\230\244", 10) 48 CODE 49 50 assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254\353\236 \354\225\204...", result 26 51 end 27 52