onebox 1.9.24 → 1.9.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf558389e0bd7431942769ee39ee40f770245463e97e25400accfe3a130af77f
4
- data.tar.gz: 23d64fbf25b722401c33aac9f0230a1d9d904d9db13794041b744c7d43165bec
3
+ metadata.gz: 6261462665816f1ed15b3da351e0fa160342038955023b1548be3af10ebd3a96
4
+ data.tar.gz: 70174996ce5669ff406f2970bec253112dadcfababe3caeaa4f35f615379629c
5
5
  SHA512:
6
- metadata.gz: 06dfe747b8a6408ef1a34c07410f32baf4d94d1cf986edee4e5267daa2eb81278569e1263bc2c9565f20ac123f93c5ca35d324f3eba6140044cfb6169b499652
7
- data.tar.gz: 1e6c04cea5599d7d1121c7e6ff502ca0d723fd3037e1955289ff26dce5eb74350db399ffa9293d7f9286971ef9b3cf5e88409ef30eeb454675b738c8924e1c64
6
+ metadata.gz: e120c498fc253c6863a6437282d5d922c6a89e6c23b59144441326c1c2f4bcf1ab33a215873e07a6d7bd2a6b51d32ac6b7ad592e58b3bb6798e44e1cf07c30cd
7
+ data.tar.gz: d245616280be4f55c0a245a7466aef9a7290cd48b7abec83a2120c664dc8ed1e117cbd02226fa4c0c6bb49ccb5250dd5e3e5e6161cbb4c78fb41858a37961438
@@ -0,0 +1,39 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby:
16
+ - 2.4
17
+ - 2.5
18
+ - 2.6
19
+
20
+ steps:
21
+ - uses: actions/checkout@v1
22
+
23
+ - name: Setup ruby
24
+ uses: actions/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ architecture: 'x64'
28
+
29
+ - name: Setup bundler
30
+ run: gem install bundler
31
+
32
+ - name: Setup gems
33
+ run: bundle install
34
+
35
+ - name: Rubocop
36
+ run: bundle exec rubocop
37
+
38
+ - name: RSpec
39
+ run: bundle exec rspec
@@ -15,7 +15,7 @@ module Onebox
15
15
 
16
16
  def url
17
17
  if match && match[:id]
18
- return "https://www.amazon.#{tld}/gp/aw/d/#{URI::encode(match[:id])}"
18
+ return "https://www.amazon.#{tld}/gp/aw/d/#{Onebox::Helpers.uri_encode(match[:id])}"
19
19
  end
20
20
 
21
21
  @url
@@ -13,11 +13,11 @@ module Onebox
13
13
  og = get_opengraph
14
14
 
15
15
  if !og.image.nil?
16
- return image_html(og)
16
+ image_html(og)
17
17
  elsif og.title.to_s[/\.(mp4|ogv|webm)$/]
18
- return video_html(og)
18
+ video_html(og)
19
19
  else
20
- return link_html(og)
20
+ link_html(og)
21
21
  end
22
22
  end
23
23
 
@@ -20,7 +20,7 @@ module Onebox
20
20
  "https://raw.githubusercontent.com/#{m[:user]}/#{m[:repo]}/#{m[:sha1]}/#{m[:file]}"
21
21
  end
22
22
  def title
23
- Sanitize.fragment(URI.unescape(link).sub(/^https?\:\/\/github\.com\//, ''))
23
+ Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/github\.com\//, ''))
24
24
  end
25
25
  end
26
26
  end
@@ -20,7 +20,7 @@ module Onebox
20
20
  "https://gitlab.com/#{m[:user]}/#{m[:repo]}/raw/#{m[:sha1]}/#{m[:file]}"
21
21
  end
22
22
  def title
23
- Sanitize.fragment(URI.unescape(link).sub(/^https?\:\/\/gitlab\.com\//, ''))
23
+ Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/gitlab\.com\//, ''))
24
24
  end
25
25
  end
26
26
  end
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "addressable"
4
+
3
5
  module Onebox
4
6
  module Helpers
5
7
 
6
8
  class DownloadTooLarge < StandardError; end
7
9
 
10
+ IGNORE_CANONICAL_DOMAINS ||= ['www.instagram.com']
11
+
8
12
  def self.symbolize_keys(hash)
9
13
  return {} if hash.nil?
10
14
 
@@ -23,12 +27,15 @@ module Onebox
23
27
  def self.fetch_html_doc(url, headers = nil)
24
28
  response = (fetch_response(url, nil, nil, headers) rescue nil)
25
29
  doc = Nokogiri::HTML(response)
30
+ uri = URI(url)
31
+
32
+ ignore_canonical_tag = doc.at('meta[property="og:ignore_canonical"]')
33
+ should_ignore_canonical = IGNORE_CANONICAL_DOMAINS.map { |hostname| uri.hostname.match?(hostname) }.any?
26
34
 
27
- ignore_canonical = doc.at('meta[property="og:ignore_canonical"]')
28
- unless ignore_canonical && ignore_canonical['content'].to_s == 'true'
35
+ unless (ignore_canonical_tag && ignore_canonical_tag['content'].to_s == 'true') || should_ignore_canonical
29
36
  # prefer canonical link
30
37
  canonical_link = doc.at('//link[@rel="canonical"]/@href')
31
- if canonical_link && "#{URI(canonical_link).host}#{URI(canonical_link).path}" != "#{URI(url).host}#{URI(url).path}"
38
+ if canonical_link && "#{URI(canonical_link).host}#{URI(canonical_link).path}" != "#{uri.host}#{uri.path}"
32
39
  response = (fetch_response(canonical_link, nil, nil, headers) rescue nil)
33
40
  doc = Nokogiri::HTML(response) if response
34
41
  end
@@ -188,56 +195,25 @@ module Onebox
188
195
  src
189
196
  end
190
197
 
191
- RFC_3986_URI_REGEX ||= /^(?<scheme>([^:\/?#]+):)?(?<authority>\/\/([^\/?#]*))?(?<path>[^?#]*)(\?(?<query>[^#]*))?(#(?<fragment>.*))?$/
192
- DOUBLE_ESCAPED_REGEXP ||= /%25([0-9a-f]{2})/i
193
-
194
- # Percent-encodes a URI query parameter per RFC3986 - https://tools.ietf.org/html/rfc3986
195
- def self.uri_query_encode(query_string)
196
- return "" unless query_string
197
-
198
- # query can encode space to %20 OR +
199
- # + MUST be encoded as %2B
200
- # in RFC3968 both query and fragment are defined as:
201
- # = *( pchar / "/" / "?" )
202
- # CGI.escape turns space into + which is the most backward compatible
203
- # however it doesn't roundtrip through URI.unescape which prefers %20
204
- CGI.escape(query_string).gsub('%25', '%').gsub('+', '%20')
205
- end
206
-
207
198
  # Percent-encodes a URI string per RFC3986 - https://tools.ietf.org/html/rfc3986
208
199
  def self.uri_encode(url)
209
200
  return "" unless url
210
201
 
211
- # parse uri into named matches, then reassemble properly encoded
212
- parts = url.match(RFC_3986_URI_REGEX)
213
-
214
- encoded = ""
215
- encoded += parts[:scheme] unless parts[:scheme].nil?
216
- encoded += parts[:authority] unless parts[:authority].nil?
217
-
218
- # path requires space to be encoded as %20 (NEVER +)
219
- # + should be left unencoded
220
- # URI::parse and URI::Generic.build don't like paths encoded with CGI.escape
221
- # URI.escape does not change / to %2F and : to %3A like CGI.escape
222
- encoded += URI.escape(parts[:path]) unless parts[:path].nil?
223
- encoded.gsub!(DOUBLE_ESCAPED_REGEXP, '%\1')
224
-
225
- # each query parameter
226
- if !parts[:query].nil?
227
- query_string = parts[:query].split('&').map do |pair|
228
- # can optionally be separated by an =
229
- pair.split('=').map do |v|
230
- uri_query_encode(v)
231
- end.join('=')
232
- end.join('&')
233
- encoded += '?' + query_string
234
- end
202
+ uri = Addressable::URI.parse(url)
235
203
 
236
- unless parts[:fragment].nil?
237
- encoded += '#' + uri_query_encode(parts[:fragment])&.gsub('%21%2F', '!/')
238
- end
204
+ encoded_uri = Addressable::URI.new(
205
+ scheme: Addressable::URI.encode_component(uri.scheme, Addressable::URI::CharacterClasses::SCHEME),
206
+ authority: Addressable::URI.encode_component(uri.authority, Addressable::URI::CharacterClasses::AUTHORITY),
207
+ path: Addressable::URI.encode_component(uri.path, Addressable::URI::CharacterClasses::PATH + "\\%"),
208
+ query: Addressable::URI.encode_component(uri.query, "a-zA-Z0-9\\-\\.\\_\\~\\$\\&\\*\\,\\=\\:\\@\\?\\%"),
209
+ fragment: Addressable::URI.encode_component(uri.fragment, "a-zA-Z0-9\\-\\.\\_\\~\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=\\:\\/\\?\\%")
210
+ )
211
+
212
+ encoded_uri.to_s
213
+ end
239
214
 
240
- encoded
215
+ def self.uri_unencode(url)
216
+ Addressable::URI.unencode(url)
241
217
  end
242
218
 
243
219
  def self.video_placeholder_html
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onebox
4
- VERSION = "1.9.24"
4
+ VERSION = "1.9.25"
5
5
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.files = `git ls-files`.split($/).reject { |s| s =~ /^(spec|web)/ }
21
21
  spec.require_paths = ['lib']
22
22
 
23
+ spec.add_runtime_dependency 'addressable', '~> 2.7.0'
23
24
  spec.add_runtime_dependency 'multi_json', '~> 1.11'
24
25
  spec.add_runtime_dependency 'mustache'
25
26
  spec.add_runtime_dependency 'nokogiri', '~> 1.7'
@@ -32,7 +33,7 @@ Gem::Specification.new do |spec|
32
33
  spec.add_development_dependency 'fakeweb', '~> 1.3'
33
34
  spec.add_development_dependency 'pry', '~> 0.10'
34
35
  spec.add_development_dependency 'mocha', '~> 1.1'
35
- spec.add_development_dependency 'rubocop', '~> 0.69.0'
36
+ spec.add_development_dependency 'rubocop', '~> 0.78.0'
36
37
  spec.add_development_dependency 'rubocop-discourse', '~> 1.0.1'
37
38
  spec.add_development_dependency 'twitter', '~> 4.8'
38
39
  spec.add_development_dependency 'guard-rspec', '~> 4.2.8'
@@ -1,9 +1,9 @@
1
- <h3><a href="{{link}}" target="_blank">{{title}}</a></h3>
1
+ <h3><a href="{{{link}}}" target="_blank">{{title}}</a></h3>
2
2
 
3
3
  {{#image}}
4
4
  <div class="instagram-images">
5
- {{#video_link}} <a href="{{video_link}}" target="_blank"> {{/video_link}}
6
- <img class="instagram-image" src="{{image}}"/>
5
+ {{#video_link}} <a href="{{{video_link}}}" target="_blank"> {{/video_link}}
6
+ <img class="instagram-image" src="{{{image}}}"/>
7
7
  {{#video_link}} <span class="instagram-video-icon"></span></a> {{/video_link}}
8
8
  </div>
9
9
  {{/image}}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.24
4
+ version: 1.9.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-11-27 00:00:00.000000000 Z
13
+ date: 2020-01-13 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: addressable
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 2.7.0
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: multi_json
17
31
  requirement: !ruby/object:Gem::Requirement
@@ -172,14 +186,14 @@ dependencies:
172
186
  requirements:
173
187
  - - "~>"
174
188
  - !ruby/object:Gem::Version
175
- version: 0.69.0
189
+ version: 0.78.0
176
190
  type: :development
177
191
  prerelease: false
178
192
  version_requirements: !ruby/object:Gem::Requirement
179
193
  requirements:
180
194
  - - "~>"
181
195
  - !ruby/object:Gem::Version
182
- version: 0.69.0
196
+ version: 0.78.0
183
197
  - !ruby/object:Gem::Dependency
184
198
  name: rubocop-discourse
185
199
  requirement: !ruby/object:Gem::Requirement
@@ -287,11 +301,11 @@ executables: []
287
301
  extensions: []
288
302
  extra_rdoc_files: []
289
303
  files:
304
+ - ".github/workflows/ci.yml"
290
305
  - ".gitignore"
291
306
  - ".rspec"
292
307
  - ".rubocop.yml"
293
308
  - ".ruby-gemset"
294
- - ".travis.yml"
295
309
  - CHANGELOG.md
296
310
  - Gemfile
297
311
  - Guardfile
@@ -421,7 +435,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
421
435
  - !ruby/object:Gem::Version
422
436
  version: '0'
423
437
  requirements: []
424
- rubygems_version: 3.0.4
438
+ rubygems_version: 3.1.2
425
439
  signing_key:
426
440
  specification_version: 4
427
441
  summary: A gem for generating embeddable HTML previews from URLs.
@@ -1,17 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 2.4
5
- - 2.5
6
- - 2.6
7
- notifications:
8
- email:
9
- on_success: change
10
- on_failure: change
11
- script:
12
- - bundle exec rubocop
13
- - bundle exec rspec
14
- cache:
15
- bundler: true
16
- before_install:
17
- - gem install bundler