aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/text_helper_test.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-09-19 21:36:36 +0000
committerJamis Buck <jamis@37signals.com>2005-09-19 21:36:36 +0000
commit390280b842605d78ec1ab968605e5968677c9400 (patch)
treeeb9c062d3043c2a4e510a2e7afd89d89f1d45a52 /actionpack/test/template/text_helper_test.rb
parent5da4c397826b26368efdd0eefc433f990bc90345 (diff)
downloadrails-390280b842605d78ec1ab968605e5968677c9400.tar.gz
rails-390280b842605d78ec1ab968605e5968677c9400.tar.bz2
rails-390280b842605d78ec1ab968605e5968677c9400.zip
Make the truncate() helper multi-byte safe (assuming $KCODE has been set to something other than "NONE") #2103
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2265 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/template/text_helper_test.rb')
-rw-r--r--actionpack/test/template/text_helper_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 383e9f64f8..856c32c300 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require "#{File.dirname(__FILE__)}/../testing_sandbox"
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/numeric' # for human_size
require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/hash' # for stringify_keys
@@ -7,6 +8,7 @@ require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/cor
class TextHelperTest < Test::Unit::TestCase
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
+ include TestingSandbox
def setup
# This simulates the fact that instance variables are reset every time
@@ -25,6 +27,29 @@ class TextHelperTest < Test::Unit::TestCase
assert_equal "Hello Worl...", truncate("Hello World!!", 12)
end
+ def test_truncate_multibyte_without_kcode
+ result = execute_in_sandbox(<<-'CODE')
+ require "#{File.dirname(__FILE__)}/../lib/action_view/helpers/text_helper"
+ include ActionView::Helpers::TextHelper
+ truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
+ CODE
+
+ assert_equal "\354\225\210\353\205\225\355\225...", result
+ end
+
+ def test_truncate_multibyte_with_kcode
+ result = execute_in_sandbox(<<-'CODE')
+ $KCODE = "u"
+ require 'jcode'
+
+ require "#{File.dirname(__FILE__)}/../lib/action_view/helpers/text_helper"
+ include ActionView::Helpers::TextHelper
+ 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)
+ CODE
+
+ assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254\353\236 \354\225\204...", result
+ end
+
def test_strip_links
assert_equal "on my mind", strip_links("<a href='almost'>on my mind</a>")
end