{"action":"opened","issue":{"url":"https://api.github.com/repos/arkhitech/redmine_timesheet_plugin/issues/64","repository_url":"https://api.github.com/repos/arkhitech/redmine_timesheet_plugin","labels_url":"https://api.github.com/repos/arkhitech/redmine_timesheet_plugin/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/arkhitech/redmine_timesheet_plugin/issues/64/comments","events_url":"https://api.github.com/repos/arkhitech/redmine_timesheet_plugin/issues/64/events","html_url":"https://github.com/arkhitech/redmine_timesheet_plugin/issues/64","id":154176746,"number":64,"title":"CSV export fails when (sub-)project name contains whitespaces","user":{"login":"catabu1","id":7932209,"avatar_url":"https://avatars.githubusercontent.com/u/7932209?v=3","gravatar_id":"","url":"https://api.github.com/users/catabu1","html_url":"https://github.com/catabu1","followers_url":"https://api.github.com/users/catabu1/followers","following_url":"https://api.github.com/users/catabu1/following{/other_user}","gists_url":"https://api.github.com/users/catabu1/gists{/gist_id}","starred_url":"https://api.github.com/users/catabu1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/catabu1/subscriptions","organizations_url":"https://api.github.com/users/catabu1/orgs","repos_url":"https://api.github.com/users/catabu1/repos","events_url":"https://api.github.com/users/catabu1/events{/privacy}","received_events_url":"https://api.github.com/users/catabu1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-11T07:23:39Z","updated_at":"2016-05-11T07:23:39Z","closed_at":null,"body":"Only confirmed for subprojects. There is a problem when the timesheet should be exported to csv and the time_entries are sorted by project. \r\n\r\nThe following is a related entry from the production log:\r\n\r\n```\r\nCompleted 500 Internal Server Error in 227ms (ActiveRecord: 47.0ms)\r\n\r\nNoMethodError (undefined method `name' for \"Project / Subproject with Whitespaces\":String):\r\n  app/models/project.rb:551:in `<=>'\r\n  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `<=>'\r\n  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `sort'\r\n  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `block in to_csv'\r\n  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:153:in `to_csv'\r\n  plugins/redmine_timesheet_plugin/app/controllers/timesheet_controller.rb:87:in `block (2 levels) in report'\r\n  plugins/redmine_timesheet_plugin/app/controllers/timesheet_controller.rb:85:in `report'\r\n  lib/redmine/sudo_mode.rb:63:in `sudo_mode'\r\n  plugins/redmine_dmsf/lib/redmine_dmsf/webdav/no_parse.rb:33:in `call'\r\n```\r\n\r\nI changed the line that's sorting the entries in the method to_csv to the following, which fixed my issues:\r\n\r\n```\r\ndiff --git a/app/models/timesheet.rb b/app/models/timesheet.rb\r\nindex 84196d9..0e7b43e 100644\r\n--- a/app/models/timesheet.rb\r\n+++ b/app/models/timesheet.rb\r\n@@ -162,7 +162,7 @@ class Timesheet\r\n           end\r\n         end\r\n       when :issue\r\n-        time_entries.sort.each do |project, entries|\r\n+        time_entries.sort {|a,b| a[0].to_s <=> b[0].to_s}.each do |project, entries|\r\n           entries[:issues].sort {|a,b| a[0].id <=> b[0].id}.each do |issue, time_entries|\r\n             time_entries.each do |e|\r\n               csv << time_entry_to_csv(e)\r\n```\r\n\r\nI'm no expert on ruby and I don't know if that's the cleanest solution possible (hence no pull request), but that's what fixed it for me for now."}}