diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-22 18:21:54 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-22 18:21:54 +0000 |
commit | 9686dcdb5b0cefe2ab80ac457917025848afb9b3 (patch) | |
tree | 84df465aa201d46605dfee61e69f03cfc1a670cd /actionpack/lib/action_view | |
parent | 286bd9b9f064fbfb67a9518f8b5216d03c496312 (diff) | |
download | rails-9686dcdb5b0cefe2ab80ac457917025848afb9b3.tar.gz rails-9686dcdb5b0cefe2ab80ac457917025848afb9b3.tar.bz2 rails-9686dcdb5b0cefe2ab80ac457917025848afb9b3.zip |
Fixed TextHelper#word_wrap for multiline strings with extra carrier returns (closes #8663) [seth]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7562 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/text_helper.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index e07c8c5ef3..e7a6303154 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -161,7 +161,9 @@ module ActionView # word_wrap('Once upon a time', 1) # # => Once\nupon\na\ntime def word_wrap(text, line_width = 80) - text.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip + text.split("\n").collect do |line| + line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line + end * "\n" end begin |