content_urls 0.1.9 → 0.1.10
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.
- checksums.yaml +8 -8
- data/content_urls.gemspec +1 -1
- data/lib/content_urls.rb +2 -2
- data/lib/content_urls/version.rb +1 -1
- data/spec/content_urls_spec.rb +23 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
MjFiODIwNDEyYzA0NDI4NzQ3NDEyNTYyYjUwMTI4ZDEyYzVkYTU0MA==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
YWQzOGFjY2Y1ZTZhNmEwMzNmYmIxZWY3MjVlZDM1NzQ2MzM5YjY4Mw==
|
|
7
7
|
!binary "U0hBNTEy":
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
M2I0MTQwNTk4MDVmMjg3MDg5ZDI4NmU3NWFkODk2OTljY2ViNGZiNGQ4MDgy
|
|
10
|
+
NzZmYzZiODIwYmM1MzhhYzZkZTVhZDZiOTRlZjBmZmNjYWVhMTgxODAzNTNh
|
|
11
|
+
NmNmN2ZmNTgwNTgxN2JkMDRjMWMzZTkyYmNhYjNkZWNhMjI5OWY=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
ZTA2YzQyYTMxYTM2ZTA4Mzk4YTJiYmQ3Y2IyNWFlNGY4Nzg1NTgxYzcwNjRj
|
|
14
|
+
ZWFiMTY0OWFmMzAyN2VmYTc0MTdlY2E3YjYwMTU1MmMxNDhiNjcxMWQ2MDAy
|
|
15
|
+
OGEwZTVmZDdjOWRiNmI4ZmM1YmM3NWY3MWUzM2MwZGU0OTMzOWI=
|
data/content_urls.gemspec
CHANGED
data/lib/content_urls.rb
CHANGED
|
@@ -94,7 +94,7 @@ class ContentUrls
|
|
|
94
94
|
#
|
|
95
95
|
def self.rewrite_each_url(content, type, &block)
|
|
96
96
|
if (parser = get_parser(type))
|
|
97
|
-
parser.rewrite_each_url(content) do |url|
|
|
97
|
+
content = parser.rewrite_each_url(content) do |url|
|
|
98
98
|
replacement = yield url
|
|
99
99
|
(replacement.nil? ? url : replacement)
|
|
100
100
|
end
|
|
@@ -111,7 +111,7 @@ class ContentUrls
|
|
|
111
111
|
def self.to_absolute(url, base_url)
|
|
112
112
|
return nil if url.nil?
|
|
113
113
|
|
|
114
|
-
url = URI.encode(URI.decode(url.to_s.gsub(/#[a-zA-Z0-
|
|
114
|
+
url = URI.encode(URI.decode(url.to_s.gsub(/#[a-zA-Z0-9\s_-]*$/,''))) # remove anchor
|
|
115
115
|
absolute = URI(base_url).merge(url)
|
|
116
116
|
absolute.path = '/' if absolute.path.empty?
|
|
117
117
|
absolute.to_s
|
data/lib/content_urls/version.rb
CHANGED
data/spec/content_urls_spec.rb
CHANGED
|
@@ -81,3 +81,26 @@ BASE_SAMPLE
|
|
|
81
81
|
urls[0].should eq 'http://www.example.com/about.html'
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
|
+
|
|
85
|
+
describe ContentUrls do
|
|
86
|
+
it "should not change absolute URLs when requested to make absolute URLs from relative URLs" do
|
|
87
|
+
|
|
88
|
+
html_sample =<<HTML_SAMPLE
|
|
89
|
+
<html>
|
|
90
|
+
<head>
|
|
91
|
+
<title>HTML Sample</title>
|
|
92
|
+
</head>
|
|
93
|
+
<body>
|
|
94
|
+
<h1>HTML Sample</h1>
|
|
95
|
+
<a href='http://www.example.com/about.html'>about</a>
|
|
96
|
+
</body>
|
|
97
|
+
</html>
|
|
98
|
+
HTML_SAMPLE
|
|
99
|
+
|
|
100
|
+
rewritten = ContentUrls.rewrite_each_url(html_sample, 'text/html') {|u|
|
|
101
|
+
'http://example.org/about.php'
|
|
102
|
+
}
|
|
103
|
+
urls = ContentUrls.urls(rewritten, 'text/html')
|
|
104
|
+
urls[0].should eq 'http://example.org/about.php'
|
|
105
|
+
end
|
|
106
|
+
end
|