postrank-uri 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/postrank-uri.rb +5 -1
- data/lib/postrank-uri/version.rb +1 -1
- data/spec/postrank-uri_spec.rb +35 -26
- metadata +2 -2
data/lib/postrank-uri.rb
CHANGED
@@ -134,7 +134,7 @@ module PostRank
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def hash(uri, opts = {})
|
137
|
-
Digest::MD5.hexdigest(opts[:
|
137
|
+
Digest::MD5.hexdigest(opts[:clean] == false ? uri : clean(uri))
|
138
138
|
end
|
139
139
|
|
140
140
|
def normalize(uri)
|
@@ -161,6 +161,10 @@ module PostRank
|
|
161
161
|
u.path = $1
|
162
162
|
end
|
163
163
|
|
164
|
+
if u.host =~ /tumblr\.com$/
|
165
|
+
u.path = u.path.gsub(/[^\/]+$/, '')
|
166
|
+
end
|
167
|
+
|
164
168
|
u
|
165
169
|
end
|
166
170
|
|
data/lib/postrank-uri/version.rb
CHANGED
data/spec/postrank-uri_spec.rb
CHANGED
@@ -132,6 +132,12 @@ describe PostRank::URI do
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
context "tumblr" do
|
136
|
+
it "should strip slug" do
|
137
|
+
c('http://test.tumblr.com/post/4533459403/some-text').should == 'http://test.tumblr.com/post/4533459403/'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
135
141
|
context "embedded links" do
|
136
142
|
it "should extract embedded redirects from Google News" do
|
137
143
|
u = c('http://news.google.com/news/url?sa=t&fd=R&&url=http://www.ctv.ca/CTVNews/Politics/20110111/')
|
@@ -167,6 +173,8 @@ describe PostRank::URI do
|
|
167
173
|
|
168
174
|
c('igvita.com?id=<>').should == 'http://igvita.com/?id=%3C%3E'
|
169
175
|
c('igvita.com?id="').should == 'http://igvita.com/?id=%22'
|
176
|
+
|
177
|
+
c('test.tumblr.com/post/23223/text-stub').should == 'http://test.tumblr.com/post/23223'
|
170
178
|
end
|
171
179
|
|
172
180
|
it "should clean host specific parameters" do
|
@@ -193,8 +201,8 @@ describe PostRank::URI do
|
|
193
201
|
it "should not clean the URI if requested" do
|
194
202
|
hash = '55fae8910d312b7878a3201ed653b881'
|
195
203
|
|
196
|
-
h('http://everburning.com/feed/post/1', :
|
197
|
-
h('everburning.com/feed/post/1', :
|
204
|
+
h('http://everburning.com/feed/post/1', :clean => false).should == hash
|
205
|
+
h('everburning.com/feed/post/1', :clean => false).should_not == hash
|
198
206
|
end
|
199
207
|
end
|
200
208
|
|
@@ -273,30 +281,31 @@ describe PostRank::URI do
|
|
273
281
|
end
|
274
282
|
end
|
275
283
|
|
276
|
-
context
|
277
|
-
url_list = {
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
284
|
+
context "domain extraction" do
|
285
|
+
url_list = {
|
286
|
+
"http://alex.pages.example.com" => "example.com",
|
287
|
+
"alex.pages.example.com" => "example.com",
|
288
|
+
"http://example.com/2011/04/01/blah" => "example.com",
|
289
|
+
"http://example.com" => "example.com",
|
290
|
+
"example.com" => "example.com",
|
291
|
+
"ExampLe.com" => "example.com",
|
292
|
+
"ExampLe.com:3000" => "example.com",
|
293
|
+
"http://alex.pages.example.COM" => "example.com",
|
294
|
+
"http://www.example.ag.it/2011/04/01/blah" => "example.ag.it",
|
295
|
+
"ftp://www.example.com/2011/04/01/blah" => nil,
|
296
|
+
"http://com" => nil,
|
297
|
+
"http://alex.pages.examplecom" => nil,
|
298
|
+
"example" => nil,
|
299
|
+
"http://127.0.0.1" => nil,
|
300
|
+
"localhost" => nil
|
301
|
+
}
|
302
|
+
|
303
|
+
url_list.each_pair do |url, expected_result|
|
304
|
+
it "should extract #{expected_result.inspect} from #{url}" do
|
305
|
+
u = PostRank::URI.clean(url, :raw => true)
|
306
|
+
u.domain.should == expected_result
|
307
|
+
end
|
308
|
+
end
|
300
309
|
end
|
301
310
|
end
|
302
311
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: postrank-uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ilya Grigorik
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-05 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|