Defect #36932

Handle nil return of Redmine::Themes.theme(Setting.ui_theme) in Redmine::Info.environment

Added by Mischa The Evil about 1 month ago. Updated 29 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Marius BALTEANU% Done:

0%

Category:Administration
Target version:5.0.1
Resolution:Fixed Affected version:5.0.0

Description

The code introduced in r21308 for #32116 can trigger an undefined method error in some edge-case(s). See Admininistration>Information page Internal error.
It turns out that it can happen that Setting.ui_theme.blank? returns false while Redmine::Themes.theme(Setting.ui_theme) returns nil. This is not expected while sending a message to Redmine::Themes.theme(Setting.ui_theme).javascripts.include? in source:/trunk/lib/redmine/info.rb@21529#L25.

The error can be reproduced (manually) on the console by setting a non-existing value for Setting.ui_theme like e.g. Setting.ui_theme = 'foo' and subsequently sending a message to Redmine::Info.environment. This effectively simulates the edge-case that is reported in the forum thread by Greg G.

This can be solved by changing lines 23-32 in source:/trunk/lib/redmine/info.rb@21529#L23 from:

        theme = Setting.ui_theme.blank? ? 'Default' : Setting.ui_theme.capitalize
        unless Setting.ui_theme.blank?
          theme_js  = (if Redmine::Themes.theme(Setting.ui_theme).javascripts.include?('theme')
                         ' (includes JavaScript)'
                       else
                         ''
                       end
                      )
        end
        theme_string = (theme + theme_js.to_s).to_s
to:
        theme_string = ''
        theme_string += (Setting.ui_theme.blank? ? 'Default' : Setting.ui_theme.capitalize)
        unless Setting.ui_theme.blank? ||
               Redmine::Themes.theme(Setting.ui_theme).nil? ||
               !Redmine::Themes.theme(Setting.ui_theme).javascripts.include?('theme')
          theme_string += ' (includes JavaScript)'
        end

This change also fixes the issue that the theme_js variable is defined conditionally but is unconditionally "used", which I feel is bad practice.

This issue affects 5.0.0 and current source:/trunk@21529.


Related issues

Related to Redmine - Feature #32116: Add configured theme to Redmine::Info Closed

Associated revisions

Revision 21541
Added by Marius BALTEANU 29 days ago

Handle nil return of Redmine::Themes.theme(Setting.ui_theme) in Redmine::Info.environment (#36932).

Patch by Mischa The Evil.

Revision 21542
Added by Marius BALTEANU 29 days ago

Add test for #36932.

Revision 21546
Added by Marius BALTEANU 29 days ago

Merged r21541 and r21542 to 5.0-stable (#36932).

History

#1 Updated by Mischa The Evil about 1 month ago

  • Related to Feature #32116: Add configured theme to Redmine::Info added

#2 Updated by Marius BALTEANU 29 days ago

  • Status changed from Confirmed to Resolved
  • Assignee set to Marius BALTEANU
  • Resolution set to Fixed

Committed the patch with a test.

#3 Updated by Marius BALTEANU 29 days ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF