Project

General

Profile

Patch #35076 » 0002-Prevent-hash-type-URLs-from-being-namespaced-in-Menu.patch

Jens Krämer, 2021-04-12 12:06

View differences:

lib/redmine/menu_manager.rb
180 180
          url = '#'
181 181
          options.reverse_merge!(:onclick => 'return false;')
182 182
        end
183
        link_to(h(caption), url, options)
183
        link_to(h(caption), use_absolute_controller(url), options)
184 184
      end
185 185

  
186 186
      def render_unattached_menu_item(menu_item, project)
187 187
        raise MenuError, ":child_menus must be an array of MenuItems" unless menu_item.is_a? MenuItem
188 188

  
189 189
        if menu_item.allowed?(User.current, project)
190
          link_to(menu_item.caption, menu_item.url, menu_item.html_options)
190
          link_to(menu_item.caption, use_absolute_controller(menu_item.url), menu_item.html_options)
191 191
        end
192 192
      end
193 193

  
......
232 232

  
233 233
        node.allowed?(user, project)
234 234
      end
235

  
236
      # Prevent hash type URLs (e.g. {controller: 'foo', action: 'bar}) from being namespaced
237
      # when menus are rendered from views in namespaced controllers in plugins or engines
238
      def use_absolute_controller(url)
239
        if url.is_a?(Hash) && url[:controller].present? && !url[:controller].start_with?('/')
240
          url[:controller] = "/#{url[:controller]}"
241
        end
242
        url
243
      end
235 244
    end
236 245

  
237 246
    class << self
    (1-1/1)