safe_redirection 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module SafeRedirection
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -20,7 +20,8 @@ module SafeRedirection
20
20
  end
21
21
 
22
22
  def base_path
23
- URI(base_url).path
23
+ match_data = URI(base_url).path.match(/((.*)(\/)|(.+))$/)
24
+ match_data[2] || match_data[4]
24
25
  end
25
26
 
26
27
  def relative_path(path)
@@ -13,18 +13,18 @@ describe SafeRedirection::Sanitizer do
13
13
  let(:params) { { :controller => 'home', :action => 'valid' } }
14
14
 
15
15
  it "should return this very URL" do
16
- resolver.should_receive(:recognize_path).with('valid', anything).and_return(params)
16
+ resolver.should_receive(:recognize_path).with('/valid', anything).and_return(params)
17
17
  subject.safe_url_for(valid_url).should == params
18
18
  end
19
19
  end
20
20
 
21
21
  context "with an invalid URL" do
22
22
  it "should return the default URL" do
23
- resolver.should_receive(:recognize_path).with('rubbish', anything).and_raise('ActionController::RoutingError')
23
+ resolver.should_receive(:recognize_path).with('/rubbish', anything).and_raise('ActionController::RoutingError')
24
24
  subject.safe_url_for("http://test.tld/rubbish").should == default_url
25
25
  end
26
26
 
27
- it "should return the default URL with a non-HTTP(s) scheme" do
27
+ it "should return the default URL with a non-HTTP(S) scheme" do
28
28
  subject.safe_url_for("ftp://test.tld/").should == default_url
29
29
  end
30
30
  end
@@ -33,17 +33,29 @@ describe SafeRedirection::Sanitizer do
33
33
  let(:base_url) { "http://test.tld/some/path/" }
34
34
 
35
35
  it "should try to resolve the subpath" do
36
- resolver.should_receive(:recognize_path).with('subpath', anything)
36
+ resolver.should_receive(:recognize_path).with('/subpath', anything)
37
37
  subject.safe_url_for('http://test.tld/some/path/subpath')
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
+ describe "#base_path" do
43
+ context "with a trailing slash" do
44
+ let(:base_url) { "http://test.tld/some/path/" }
45
+ its(:base_path) { should == "/some/path" }
46
+ end
47
+
48
+ context "without a trailing slash" do
49
+ let(:base_url) { "http://test.tld/some/path" }
50
+ its(:base_path) { should == "/some/path" }
51
+ end
52
+ end
53
+
42
54
  describe "#relative_path" do
43
55
  let(:base_url) { "http://test.tld/in/so.me/path/" }
44
56
 
45
57
  it "should strip the base path" do
46
- subject.relative_path('/in/so.me/path/subpath').should == 'subpath'
58
+ subject.relative_path('/in/so.me/path/subpath').should == '/subpath'
47
59
  end
48
60
 
49
61
  it "should not strip it if it's not in the beginning" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe_redirection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-12 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -104,5 +104,5 @@ rubyforge_project:
104
104
  rubygems_version: 1.8.24
105
105
  signing_key:
106
106
  specification_version: 3
107
- summary: safe_redirection-0.0.1
107
+ summary: safe_redirection-0.0.2
108
108
  test_files: []