From c679593d1e375b40f2563691ee82c485c69dc6d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Witrant?= Date: Sat, 14 Nov 2009 18:18:00 +0800 Subject: [PATCH] fixed url parsing when they contain a slash in query string --- config/initializers/core_ext.rb | 25 ++++++++++++++++++++++++ test/functional/todos_controller_test.rb | 12 ++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 config/initializers/core_ext.rb diff --git a/config/initializers/core_ext.rb b/config/initializers/core_ext.rb new file mode 100644 index 00000000..507a0cf3 --- /dev/null +++ b/config/initializers/core_ext.rb @@ -0,0 +1,25 @@ +# See test_url_with_slash_in_query_string_are_parsed_correctly in test/functional/todos_controller_test.rb +# and http://blog.swivel.com/code/2009/06/rails-auto_link-and-certain-query-strings.html +module ActionView::Helpers::TextHelper + remove_const :AUTO_LINK_RE + AUTO_LINK_RE = %r{ + ( # leading text + <\w+.*?>| # leading HTML tag, or + [^=!:'"/]| # leading punctuation, or + ^ # beginning of line + ) + ( + (?:https?://)| # protocol spec, or + (?:www\.) # www.* + ) + ( + [-\w]+ # subdomain or domain + (?:\.[-\w]+)* # remaining subdomains or domain + (?::\d+)? # port + (?:/(?:[~\w\+@%=\(\)-]|(?:[,.;:'][^\s$]))*)* # path + (?:\?[\w\+@%&=.;:/-]+)? # query string + (?:\#[\w\-]*)? # trailing anchor + ) + ([[:punct:]]|<|$|) # trailing text + }x +end diff --git a/test/functional/todos_controller_test.rb b/test/functional/todos_controller_test.rb index e65c67a6..c59ff232 100644 --- a/test/functional/todos_controller_test.rb +++ b/test/functional/todos_controller_test.rb @@ -519,5 +519,17 @@ class TodosControllerTest < ActionController::TestCase todo.reload() assert_equal "active", todo.state end + + def test_url_with_slash_in_query_string_are_parsed_correctly + # See http://blog.swivel.com/code/2009/06/rails-auto_link-and-certain-query-strings.html + login_as(:admin_user) + user = users(:admin_user) + todo = user.todos.first + url = "http://example.com/foo?bar=/baz" + todo.notes = "foo #{url} bar" + todo.save! + get :index + assert_select("a[href=#{url}]") + end end