Topic: Leading slash removed from controller, possible bug?

There appears to be a problem with url_for in Rails 3.2.2 that it will delete a leading forward slash from the string sent as the controller name. Here are a test case to illustrate:

require 'test_helper'

class AppHelperTest < ActionView::TestCase
  include ApplicationHelper
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::TagHelper

  def test_url_for
    s = '/notes'
    url_for :controller => s
    assert_equal '/notes', s
  end
end

What should happen (well, in my opinion, anyway) is that s is unchanged by the call to url_to, but what actually happens is that s is changed to "notes".

Delving into Rails, the problem is due to this line in actionpack-3.2.2\lib\action_dispatch\routing\route_set.rb:

controller.sub!(%r{^/}, '') if controller

I had thought i can be fixed by appending .dup here (just a few lines lower in the same file):

        def controller
          @controller ||= @options[:controller].dup
        end

... but this breaks things else where.

Running on Rails version 3.2.2, with Ruby 1.9.2, on JRuby 1.6.7

Last edited by F2Andy (2012-06-06 06:41:34)