]> source.dussan.org Git - redmine.git/commitdiff
Ruby 1.9 compatibility of unified_diff.rb.
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Mon, 21 Feb 2011 03:59:50 +0000 (03:59 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Mon, 21 Feb 2011 03:59:50 +0000 (03:59 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4897 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/unified_diff.rb

index 09fbfcf1a9dd5a6d7cd1eab311ea4467ced6a956..65d880dd77e40355a0f1831aa63029d16956445f 100644 (file)
@@ -22,12 +22,20 @@ module Redmine
       options.assert_valid_keys(:type, :max_lines)
       diff = diff.split("\n") if diff.is_a?(String)
       diff_type = options[:type] || 'inline'
-      
       lines = 0
       @truncated = false
       diff_table = DiffTable.new(diff_type)
       diff.each do |line|
+        line_encoding = nil
+        if line.respond_to?(:force_encoding)
+          line_encoding = line.encoding
+          # TODO: UTF-16 and Japanese CP932 which is imcompatible with ASCII
+          #       In Japan, diffrence between file path encoding
+          #       and file contents encoding is popular.
+          line.force_encoding('ASCII-8BIT')
+        end
         unless diff_table.add_line line
+          line.force_encoding(line_encoding) if line_encoding
           self << diff_table if diff_table.length > 1
           diff_table = DiffTable.new(diff_type)
         end
@@ -40,7 +48,7 @@ module Redmine
       self << diff_table unless diff_table.empty?
       self
     end
-    
+
     def truncated?; @truncated; end
   end