unshorten 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/unshorten.rb CHANGED
@@ -11,7 +11,7 @@ class Unshorten
11
11
  DEFAULT_OPTIONS = {
12
12
  :max_level => 10,
13
13
  :timeout => 2,
14
- :short_hosts => /.*/,
14
+ :short_hosts => Regexp.union('url', /^[^.]{1,6}\.[^.]{1,2}$/i),
15
15
  :use_cache => true,
16
16
  :add_missing_http => true
17
17
  }
@@ -68,9 +68,9 @@ class Unshorten
68
68
  return @@cache[url] if options[:use_cache] and @@cache[url]
69
69
  return url if level >= options[:max_level]
70
70
 
71
- uri = URI.parse(url)
71
+ uri = URI.parse(url) rescue nil
72
72
 
73
- return url unless uri.host =~ options[:short_hosts]
73
+ return url if uri.nil? or not uri.host =~ options[:short_hosts]
74
74
 
75
75
  http = Net::HTTP.new(uri.host, uri.port)
76
76
  http.read_timeout = options[:timeout]
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  require 'test/unit'
2
4
  require 'unshorten'
3
5
 
@@ -9,6 +11,11 @@ class UnshortenTest < Test::Unit::TestCase
9
11
  assert_equal ORIGINAL_URL, Unshorten[SHORTENED_URL, :use_cache => false]
10
12
  end
11
13
 
14
+ def test_illegal_urls
15
+ illegal_url = 'http://a汉字bc.那么/是非法的?url'
16
+ assert_equal illegal_url, Unshorten.unshorten(illegal_url, :use_cache => false)
17
+ end
18
+
12
19
  def test_option_max_level
13
20
  assert_equal SHORTENED_URL, Unshorten.unshorten(SHORTENED_URL, :max_level => 0, :use_cache => false)
14
21
  end
@@ -16,4 +23,5 @@ class UnshortenTest < Test::Unit::TestCase
16
23
  def test_option_short_hosts
17
24
  assert_equal SHORTENED_URL, Unshorten.unshorten(SHORTENED_URL, :short_hosts => /jmp/, :use_cache => false)
18
25
  end
26
+
19
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unshorten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: