]> source.dussan.org Git - redmine.git/commitdiff
Fix Trac importer breaking on exotic characters with ruby 1.9+ (#13990).
authorJean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Mon, 6 May 2013 22:19:37 +0000 (22:19 +0000)
committerJean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Mon, 6 May 2013 22:19:37 +0000 (22:19 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11796 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/tasks/migrate_from_trac.rake

index 406a5b221a287637337401ed4ec1f22db0204c28..ddc77fb344e619f45008caabecd4c2373c5590db 100644 (file)
@@ -153,7 +153,11 @@ namespace :redmine do
       private
         def trac_fullpath
           attachment_type = read_attribute(:type)
-          trac_file = filename.gsub( /[^a-zA-Z0-9\-_\.!~*']/n ) {|x| sprintf('%%%02x', x[0]) }
+          #replace exotic characters with their hex representation to avoid invalid filenames
+          trac_file = filename.gsub( /[^a-zA-Z0-9\-_\.!~*']/n ) do |x|
+            codepoint = RUBY_VERSION < '1.9' ? x[0] : x.codepoints.to_a[0]
+            sprintf('%%%02x', codepoint)
+          end
           "#{TracMigrate.trac_attachments_directory}/#{attachment_type}/#{id}/#{trac_file}"
         end
       end