Skip to content

Commit

Permalink
fix generation of page URLs that contain the "@" character
Browse files Browse the repository at this point in the history
before, "/blogs/@Andrex/page/2" would be generated like "/blogs/2Andrex/page/@"
[mislav#262 state:resolved]
  • Loading branch information
KURODA Hiraku authored and mislav committed May 20, 2009
1 parent b63e438 commit 1142ac9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/will_paginate/view_helpers.rb
Expand Up @@ -332,21 +332,21 @@ def url_for(page)
return url if page_one

if complex
@url_string = url.sub(%r!((?:\?|&)#{CGI.escape param_name}=)#{page}!, '\1@')
@url_string = url.sub(%r!((?:\?|&)#{CGI.escape param_name}=)#{page}!, "\\1\0")
return url
else
@url_string = url
@url_params[param_name] = 3
@template.url_for(@url_params).split(//).each_with_index do |char, i|
if char == '3' and url[i, 1] == '2'
@url_string[i] = '@'
@url_string[i] = "\0"
break
end
end
end
end
# finally!
@url_string.sub '@', page.to_s
@url_string.sub "\0", page.to_s
end

private
Expand Down
8 changes: 8 additions & 0 deletions test/view_test.rb
Expand Up @@ -277,6 +277,14 @@ def test_will_paginate_with_custom_page_param
end
end
end

def test_will_paginate_with_atmark_url
@request.symbolized_path_parameters[:action] = "@tag"
renderer = WillPaginate::LinkRenderer.new

paginate({ :page => 1 }, :renderer=>renderer)
assert_links_match %r[/foo/@tag\?page=\d]
end

def test_complex_custom_page_param
@request.params :developers => { :page => 2 }
Expand Down

0 comments on commit 1142ac9

Please sign in to comment.