Skip to content

Commit

Permalink
Compare unencoded URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Gast committed Jun 27, 2011
1 parent 66098fc commit bf1edeb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/simple_navigation/adapters/sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def current_page?(url)
else
uri = request_uri.split('?').first
end
uri = CGI.unescape(uri)
if url_string =~ /^\w+:\/\//
url_string == "#{request.scheme}://#{request.host_with_port}#{uri}"
else
Expand Down
37 changes: 28 additions & 9 deletions spec/lib/simple_navigation/adapters/sinatra_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,34 @@ def create_adapter
before(:each) do
@request.stub!(:scheme => 'http', :host_with_port => 'my_host:5000')
end
it {@adapter.current_page?('/full?param=true').should be_true}
it {@adapter.current_page?('/full?param3=true').should be_false}
it {@adapter.current_page?('/full').should be_true}
it {@adapter.current_page?('http://my_host:5000/full?param=true').should be_true}
it {@adapter.current_page?('http://my_host:5000/full?param3=true').should be_false}
it {@adapter.current_page?('http://my_host:5000/full').should be_true}
it {@adapter.current_page?('https://my_host:5000/full').should be_false}
it {@adapter.current_page?('http://my_host:6000/full').should be_false}
it {@adapter.current_page?('http://my_other_host:5000/full').should be_false}

describe 'when URL is not encoded' do
it {@adapter.current_page?('/full?param=true').should be_true}
it {@adapter.current_page?('/full?param3=true').should be_false}
it {@adapter.current_page?('/full').should be_true}
it {@adapter.current_page?('http://my_host:5000/full?param=true').should be_true}
it {@adapter.current_page?('http://my_host:5000/full?param3=true').should be_false}
it {@adapter.current_page?('http://my_host:5000/full').should be_true}
it {@adapter.current_page?('https://my_host:5000/full').should be_false}
it {@adapter.current_page?('http://my_host:6000/full').should be_false}
it {@adapter.current_page?('http://my_other_host:5000/full').should be_false}
end

describe 'when URL is encoded' do
before(:each) do
@request.stub!(:fullpath => '/full%20with%20spaces?param=true', :path => '/full%20with%20spaces')
end

it {@adapter.current_page?('/full%20with%20spaces?param=true').should be_true}
it {@adapter.current_page?('/full%20with%20spaces?param3=true').should be_false}
it {@adapter.current_page?('/full%20with%20spaces').should be_true}
it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces?param=true').should be_true}
it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces?param3=true').should be_false}
it {@adapter.current_page?('http://my_host:5000/full%20with%20spaces').should be_true}
it {@adapter.current_page?('https://my_host:5000/full%20with%20spaces').should be_false}
it {@adapter.current_page?('http://my_host:6000/full%20with%20spaces').should be_false}
it {@adapter.current_page?('http://my_other_host:5000/full%20with%20spaces').should be_false}
end
end

describe 'link_to' do
Expand Down

0 comments on commit bf1edeb

Please sign in to comment.