absolutize 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -1
- data/lib/absolutize.rb +3 -3
- data/lib/absolutize.rb~ +3 -3
- data/spec/absolutize/absolutize_spec.rb +49 -26
- data/spec/absolutize/absolutize_spec.rb~ +49 -24
- metadata +3 -3
data/README.textile
CHANGED
data/lib/absolutize.rb
CHANGED
@@ -8,9 +8,9 @@ class Absolutize
|
|
8
8
|
@base_url = base_url
|
9
9
|
@options = options
|
10
10
|
|
11
|
-
@options[:remove_anchors] = false
|
12
|
-
@options[:force_escaping] = true
|
13
|
-
@options[:output_debug] = false
|
11
|
+
@options[:remove_anchors] = false if @options[:remove_anchors].nil?
|
12
|
+
@options[:force_escaping] = true if @options[:force_escaping].nil?
|
13
|
+
@options[:output_debug] = false if @options[:output_debug].nil?
|
14
14
|
end
|
15
15
|
|
16
16
|
def url(relative_url)
|
data/lib/absolutize.rb~
CHANGED
@@ -8,9 +8,9 @@ class Absolutize
|
|
8
8
|
@base_url = base_url
|
9
9
|
@options = options
|
10
10
|
|
11
|
-
@options[:remove_anchors] = false
|
12
|
-
@options[:force_escaping] = true
|
13
|
-
@options[:output_debug] = false
|
11
|
+
@options[:remove_anchors] = false if @options[:remove_anchors].nil?
|
12
|
+
@options[:force_escaping] = true if @options[:force_escaping].nil?
|
13
|
+
@options[:output_debug] = false if @options[:output_debug].nil?
|
14
14
|
end
|
15
15
|
|
16
16
|
def url(relative_url)
|
@@ -3,36 +3,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe Absolutize do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@base_url = "http://www.baseurl.com/"
|
7
|
-
@absolutize = Absolutize.new(@base_url)
|
6
|
+
@base_url = "http://www.baseurl.com/"
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
describe "with default parameters" do
|
10
|
+
before(:each) do
|
11
|
+
@absolutize = Absolutize.new(@base_url)
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
it "should create an Absolutize object" do
|
15
|
+
@absolutize.should be_an_instance_of Absolutize
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return the same url for an absolute url" do
|
19
|
+
@absolutize.url("http://www.bbc.co.uk/").to_s.should == "http://www.bbc.co.uk/"
|
20
|
+
end
|
21
|
+
it "should return the same url for an absolute url" do
|
22
|
+
@absolutize.url("http://www.bbc.co.uk//asdf/asdf.html").to_s.should == "http://www.bbc.co.uk/asdf/asdf.html"
|
23
|
+
end
|
24
|
+
it "should return the absolute url for a relative to root url" do
|
25
|
+
@absolutize.url("/asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
|
26
|
+
end
|
27
|
+
it "should return the absolute url for a relative to folder url" do
|
28
|
+
@absolutize.url("asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
|
29
|
+
end
|
30
|
+
it "should handle urls with spaces" do
|
31
|
+
@absolutize.url("/root folder/asdf.html").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
|
32
|
+
end
|
33
|
+
it "should handle urls with ['s" do
|
34
|
+
@absolutize.url("/folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/folder/asdf.html?id=%5Basdf%5D"
|
35
|
+
end
|
36
|
+
it "should not encode urls with %'s" do
|
37
|
+
@absolutize.url("/root%20folder/asdf.html?id=asdf").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=asdf"
|
38
|
+
end
|
39
|
+
it "should not encode existing encoded characters" do
|
40
|
+
@absolutize.url("/root%20folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=%5Basdf%5D"
|
41
|
+
end
|
28
42
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
43
|
+
|
44
|
+
describe "with remove_anchors true" do
|
45
|
+
before(:each) do
|
46
|
+
@absolutize = Absolutize.new(@base_url, :remove_anchors => true)
|
47
|
+
end
|
48
|
+
it "should remove an anchor" do
|
49
|
+
@absolutize.url("/root folder/asdf.html#anchor").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
|
50
|
+
end
|
34
51
|
end
|
35
|
-
|
36
|
-
|
52
|
+
|
53
|
+
describe "with force_escaping false" do
|
54
|
+
before(:each) do
|
55
|
+
@absolutize = Absolutize.new(@base_url, :force_escaping => false)
|
56
|
+
end
|
57
|
+
it "should not escape invalid characters" do
|
58
|
+
lambda { @absolutize.url("/root folder/asdf.html#anchor")}.should raise_error
|
59
|
+
end
|
37
60
|
end
|
38
61
|
end
|
@@ -3,34 +3,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe Absolutize do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@base_url = "http://www.baseurl.com/"
|
7
|
-
@absolutize = Absolutize.new(@base_url)
|
6
|
+
@base_url = "http://www.baseurl.com/"
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
describe "with default parameters" do
|
10
|
+
before(:each) do
|
11
|
+
@absolutize = Absolutize.new(@base_url)
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
it "should create an Absolutize object" do
|
15
|
+
@absolutize.should be_an_instance_of Absolutize
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return the same url for an absolute url" do
|
19
|
+
@absolutize.url("http://www.bbc.co.uk/").to_s.should == "http://www.bbc.co.uk/"
|
20
|
+
end
|
21
|
+
it "should return the same url for an absolute url" do
|
22
|
+
@absolutize.url("http://www.bbc.co.uk//asdf/asdf.html").to_s.should == "http://www.bbc.co.uk/asdf/asdf.html"
|
23
|
+
end
|
24
|
+
it "should return the absolute url for a relative to root url" do
|
25
|
+
@absolutize.url("/asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
|
26
|
+
end
|
27
|
+
it "should return the absolute url for a relative to folder url" do
|
28
|
+
@absolutize.url("asdf.html").to_s.should == "http://www.baseurl.com/asdf.html"
|
29
|
+
end
|
30
|
+
it "should handle urls with spaces" do
|
31
|
+
@absolutize.url("/root folder/asdf.html").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
|
32
|
+
end
|
33
|
+
it "should handle urls with ['s" do
|
34
|
+
@absolutize.url("/folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/folder/asdf.html?id=%5Basdf%5D"
|
35
|
+
end
|
36
|
+
it "should not encode urls with %'s" do
|
37
|
+
@absolutize.url("/root%20folder/asdf.html?id=asdf").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=asdf"
|
38
|
+
end
|
39
|
+
it "should not encode existing encoded characters" do
|
40
|
+
@absolutize.url("/root%20folder/asdf.html?id=[asdf]").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html?id=%5Basdf%5D"
|
41
|
+
end
|
28
42
|
end
|
29
|
-
|
30
|
-
|
43
|
+
|
44
|
+
describe "with remove_anchors true" do
|
45
|
+
before(:each) do
|
46
|
+
@absolutize = Absolutize.new(@base_url, :remove_anchors => true)
|
47
|
+
end
|
48
|
+
it "should remove an anchor" do
|
49
|
+
@absolutize.url("/root folder/asdf.html#anchor").to_s.should == "http://www.baseurl.com/root%20folder/asdf.html"
|
50
|
+
end
|
31
51
|
end
|
32
|
-
|
33
|
-
|
52
|
+
|
53
|
+
describe "with force_escaping false" do
|
54
|
+
before(:each) do
|
55
|
+
@absolutize = Absolutize.new(@base_url, :force_escaping => false)
|
56
|
+
end
|
57
|
+
it "should not escape invalid characters" do
|
58
|
+
lambda { @absolutize.url("/root folder/asdf.html#anchor")}.should raise_error
|
59
|
+
end
|
34
60
|
end
|
35
|
-
|
36
61
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: absolutize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Stewart McKee
|