mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
fixed url parsing when they contain a slash in query string
This commit is contained in:
parent
45d9ab60bf
commit
c679593d1e
2 changed files with 37 additions and 0 deletions
25
config/initializers/core_ext.rb
Normal file
25
config/initializers/core_ext.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue