alphanodes / additionals

Redmine plugin for easy customization of settings, text and content display by using personal or role-based dashboards (drag&drop), providing wiki macros and act as library for other plugins.
https://www.redmine.org/plugins/additionals
GNU General Public License v2.0
131 stars 43 forks source link

Error (invalid byte sequence in UTF-8) in system_info #150

Open yxiaoa opened 1 year ago

yxiaoa commented 1 year ago

additionals/app/models/additionals_info.rb:33:in `system_info'

if Redmine::Platform.mswin? win_info = wmic os get Caption,CSDVersion,BuildNumber /value return 'unknown' if win_info.blank?

Reported error if Windows is Chinese edition

yxiaoa commented 1 year ago

wmic os get Caption,CSDVersion,BuildNumber /value

BuildNumber=19044 Caption=Microsoft Windows 10 企业版 CSDVersion=

alexandermeindl commented 1 year ago

Hi @yxiaoa

thanks for reporting this! Can you post the error message in your log? This would help to find a solution for it.

Which ruby version do you use? If you use an older version as 3, it would be interesting, if it works with ruby => 3. See https://bugs.ruby-lang.org/issues/16604

yxiaoa commented 1 year ago
Started GET "/redmine/admin/info" for 127.0.0.1 at 2022-10-22 13:02:36 +0800
Processing by AdminController#info as HTML
  Current user: xiao.yang (id=1)
Imagemagick's convert binary (D:\0_Program\3_User\Redmine/imagemagick/convert.exe) not available
gs binary (gs) not available
  Rendering admin/info.html.erb within layouts/admin
  Rendered admin/info.html.erb within layouts/admin (105.0ms)
Completed 500 Internal Server Error in 2052ms (ActiveRecord: 101.6ms)

ActionView::Template::Error (invalid byte sequence in UTF-8):
    10:   </tr>
    11: <% end %>
    12: </table><table class="list">
    13: <% AdditionalsInfo.new.system_infos.each do |type, system_info|
    14:  %><tr <% _temple_html_attributeremover1 = ''; _slim_codeattributes1 = type; if Array === _slim_codeattributes1; _slim_codeattributes1 = _slim_codeattributes1.flatten; _slim_codeattributes1.map!(&:to_s); _slim_codeattributes1.reject!(&:empty?); _temple_html_attributeremover1 << ((::Temple::Utils.escape_html_safe((_slim_codeattributes1.join(" ")))).to_s); else; _temple_html_attributeremover1 << ((::Temple::Utils.escape_html_safe((_slim_codeattributes1))).to_s); end; _temple_html_attributeremover1 %> <% if !_temple_html_attributeremover1.empty? %> class="<%= _temple_html_attributeremover1 %>" <% end %>>
    15: <td class="name">
    16: <%= ::Temple::Utils.escape_html_safe(("#{system_info[:label].presence || type}:")) %>

plugins/additionals/app/models/additionals_info.rb:33:in `system_info'
plugins/additionals/app/models/additionals_info.rb:8:in `system_infos'
app/views/admin/info.html.erb:13:in `_app_views_admin_info_html_erb__685522007_1496229931660'
lib/redmine/sudo_mode.rb:61:in `sudo_mode'

Ruby version:

ruby 2.6.7p197 (2021-04-05 revision 67941) [x64-mingw32]

I set win_info = '' instead of the returned value from wmic and it's ok. It seems that the Chinese characters in the Caption string caused this error.

alexandermeindl commented 1 year ago

Hi @yxiaoa,

Thanks for providing the additional info. With my last commit (main branch) I tried to fix the problem. Could you try it, if it works? I do not have the required testing operating system for it. It would be nice - if it works - if you can provide the displayed windows system information (which you can find on /admin/info). I want to check, if the relevant information are displayed, which I would expect.

yxiaoa commented 1 year ago

I do not have redmine 5.x, but I picked the changes based on 3.0.5.2. The error is fixed, and below is the admin information from redmine. The Chinese chars turn to messy code. I'm not sure whether it's because the redmine font doesn't match Chinese. I have Chinese characters displayed correctly on the redmine issue.

Information Redmine 4.2.1.stable

Default administrator account changed
Attachments directory writable
Plugin assets directory writable (./public/plugin_assets)
MiniMagick available (optional) ImageMagick convert available (optional)
ImageMagick PDF support available (optional)
System info: Microsoft Windows 10 ??ҵ?? build 19044 Uptime: Redmine Plugin Kit: 1.0.4

Environment: Redmine version 4.2.1.stable Ruby version 2.6.7-p197 (2021-04-05) [x64-mingw32] Rails version 5.2.5 Environment production Database adapter Mysql2 Mailer queue ActiveJob::QueueAdapters::AsyncAdapter Mailer delivery smtp SCM: Git 2.37.3 Filesystem
Redmine plugins: additionals 3.0.5.2 custom_users_as_assignees 0.0.4 redmine_agile 1.6.2 redmine_checklists 3.1.21 redmine_monitoring_controlling 0.1.1 redmine_people 1.6.2 redmineup_tags 2.0.12 worklogs 0.3.0

yxiaoa commented 1 year ago

And yeah thanks for your work. Maybe this can become low priority as the page can be displayed. The Chinese words are not so important.

alexandermeindl commented 1 year ago

Hi @yxiaoa,

thanks for your feedback!

Can you change this line:

win_info = Redmine::CodesetUtil.replace_invalid_utf8 win_info

to

win_info = win_info.force_encoding('UTF-16LE').encode('UTF-8')

If you fix the problem in your installation with the change, I would update it in additionals plugin.

yxiaoa commented 1 year ago

System info: Windows Uptime: Redmine Plugin Kit: 1.0.4

System info becomes just "Windows"

alexandermeindl commented 1 year ago

Hi @yxiaoa,

ahh, this is not the result, which I excepted.

Is it possible, if you do another try with the following change:

Change

win_info = Redmine::CodesetUtil.replace_invalid_utf8 win_info

to

win_info.encode! 'UTF-8'

The result should with your environment "Microsoft Windows 10 企业版 build 19044". If this is the case, we found the right solution ;)

Thanks in advance for your help!

yxiaoa commented 1 year ago

Hi @alexandermeindl

Still "Windows". Maybe Chinese edition Windows' language is weired😂

I think it's ok to just display "Windows" as functions are not affected. However, I'm glad to test it if any changes made.

yxiaoa commented 1 year ago

I'm not sure whether you can add some logs to check the raw hex values that wmic outputs