link_thumbnailer 2.5.2 → 2.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49bbee58589eb5ba7a8e91f3747116510331160e
4
- data.tar.gz: 8dde81b01a30960aa69febd8fe42f3bcb824b6a9
3
+ metadata.gz: 70bf3449f58e41e93e1fca01e64835b3fe150d91
4
+ data.tar.gz: 8db948511fb227d94e6afbf6721222539edd13a3
5
5
  SHA512:
6
- metadata.gz: 2031071a1077e7ad8915bfa11183e75f23a6e4e7d6a7700f661e599fa164fb2424dfa6fabd36576ca184ed97028199175d9087978514751528a68a93bc8a4c0e
7
- data.tar.gz: 4806f8bb2bdd828739e1359bcf0bf784be459f69c7d13f1ec14efbff4738cf5d770447d6f0b181f8119c548266a0c98a756936ff19e651949e5e33f6d17add01
6
+ metadata.gz: 63ab6ab4ed55873cb612257507089af4fbd8e6ed3e941e46cfb92057fa59f31a92ed3f69a9b880e189ff4296e967964dcf40f46ffc36bb4fd650517de74079e4
7
+ data.tar.gz: 28ebc45714d8695ba0b2d912858aeba54bf4fb5326318b65855d3bbc7f060c4cb004196c89224b4ce6f407dec4e9adfbb4b69d4af1413f43cb6742afad290dac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.6.0
2
+
3
+ - Introduce new `raise_on_invalid_format` option (false by default) to raise `LinkThumbnailer::FormatNotSupported` if http `Content-Type` is invalid. Fixes #61 and #64.
4
+
1
5
  # 2.5.2
2
6
 
3
7
  - Fix OpenURI::HTTPError exception raised when video_info gem is not able to parse video metadata. Fixes #60.
@@ -25,7 +25,7 @@ module LinkThumbnailer
25
25
  attr_accessor :redirect_limit, :blacklist_urls, :user_agent,
26
26
  :verify_ssl, :http_open_timeout, :http_read_timeout, :attributes,
27
27
  :graders, :description_min_length, :positive_regex, :negative_regex,
28
- :image_limit, :image_stats
28
+ :image_limit, :image_stats, :raise_on_invalid_format
29
29
 
30
30
  alias_method :http_timeout, :http_open_timeout
31
31
  alias_method :http_timeout=, :http_open_timeout=
@@ -58,6 +58,7 @@ module LinkThumbnailer
58
58
  @negative_regex = /combx|comment|com-|contact|foot|footer|footnote|masthead|media|meta|outbrain|promo|related|scroll|shoutbox|sidebar|sponsor|shopping|tags|tool|widget|modal/i
59
59
  @image_limit = 5
60
60
  @image_stats = true
61
+ @raise_on_invalid_format = false
61
62
  end
62
63
 
63
64
  end
@@ -2,5 +2,6 @@ module LinkThumbnailer
2
2
  class Exceptions < StandardError; end
3
3
  class RedirectLimit < Exceptions; end
4
4
  class BadUriFormat < Exceptions; end
5
+ class FormatNotSupported < Exceptions; end
5
6
  class ScraperInvalid < Exceptions; end
6
7
  end
@@ -1,3 +1,4 @@
1
+ require 'pry'
1
2
  require 'delegate'
2
3
  require 'uri'
3
4
  require 'net/http/persistent'
@@ -53,8 +54,11 @@ module LinkThumbnailer
53
54
  headers = {}
54
55
  headers['Cookie'] = response['Set-Cookie'] if response['Set-Cookie'].present?
55
56
 
57
+ raise ::LinkThumbnailer::FormatNotSupported.new(response['Content-Type']) unless valid_response_format?(response)
58
+
56
59
  case response
57
- when ::Net::HTTPSuccess then response.body
60
+ when ::Net::HTTPSuccess
61
+ response.body
58
62
  when ::Net::HTTPRedirection
59
63
  call(
60
64
  resolve_relative_url(response['location']),
@@ -102,6 +106,17 @@ module LinkThumbnailer
102
106
  url.is_a?(::URI::HTTP)
103
107
  end
104
108
 
109
+ def valid_response_format?(response)
110
+ return true unless config.raise_on_invalid_format
111
+ return true if response['Content-Type'] =~ /text\/html/
112
+ return true if response['Content-Type'] =~ /application\/html/
113
+ return true if response['Content-Type'] =~ /application\/xhtml\+xml/
114
+ return true if response['Content-Type'] =~ /application\/xml/
115
+ return true if response['Content-Type'] =~ /text\/xml/
116
+ return true if response['Content-Type'] =~ /text\/plain/
117
+ false
118
+ end
119
+
105
120
  def url=(url)
106
121
  @url = ::URI.parse(url.to_s)
107
122
  end
@@ -1,3 +1,3 @@
1
1
  module LinkThumbnailer
2
- VERSION = '2.5.2'
2
+ VERSION = '2.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_thumbnailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
11
+ date: 2015-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport