Skip to content

Commit

Permalink
DEV: Update Rubocop and fix found issues (#418)
Browse files Browse the repository at this point in the history
See the information about deprecations (URI.encode, URI.escape, URI.unescape, and URI.unencode) here: http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-core/29293?29179-31097)
  • Loading branch information
CvX committed Dec 27, 2019
1 parent 5f028c9 commit 8ff3fff
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/onebox/engine/amazon_onebox.rb
Expand Up @@ -15,7 +15,7 @@ class AmazonOnebox

def url
if match && match[:id]
return "https://www.amazon.#{tld}/gp/aw/d/#{URI::encode(match[:id])}"
return "https://www.amazon.#{tld}/gp/aw/d/#{Onebox::Helpers.uri_encode(match[:id])}"
end

@url
Expand Down
6 changes: 3 additions & 3 deletions lib/onebox/engine/cloudapp_onebox.rb
Expand Up @@ -13,11 +13,11 @@ def to_html
og = get_opengraph

if !og.image.nil?
return image_html(og)
image_html(og)
elsif og.title.to_s[/\.(mp4|ogv|webm)$/]
return video_html(og)
video_html(og)
else
return link_html(og)
link_html(og)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/onebox/engine/github_blob_onebox.rb
Expand Up @@ -20,7 +20,7 @@ def raw_template(m)
"https://raw.githubusercontent.com/#{m[:user]}/#{m[:repo]}/#{m[:sha1]}/#{m[:file]}"
end
def title
Sanitize.fragment(URI.unescape(link).sub(/^https?\:\/\/github\.com\//, ''))
Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/github\.com\//, ''))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/onebox/engine/gitlab_blob_onebox.rb
Expand Up @@ -20,7 +20,7 @@ def raw_template(m)
"https://gitlab.com/#{m[:user]}/#{m[:repo]}/raw/#{m[:sha1]}/#{m[:file]}"
end
def title
Sanitize.fragment(URI.unescape(link).sub(/^https?\:\/\/gitlab\.com\//, ''))
Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/gitlab\.com\//, ''))
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions lib/onebox/helpers.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "addressable"

module Onebox
module Helpers

Expand Down Expand Up @@ -217,9 +219,7 @@ def self.uri_encode(url)

# path requires space to be encoded as %20 (NEVER +)
# + should be left unencoded
# URI::parse and URI::Generic.build don't like paths encoded with CGI.escape
# URI.escape does not change / to %2F and : to %3A like CGI.escape
encoded += URI.escape(parts[:path]) unless parts[:path].nil?
encoded += Addressable::URI.encode(parts[:path]) unless parts[:path].nil?
encoded.gsub!(DOUBLE_ESCAPED_REGEXP, '%\1')

# each query parameter
Expand All @@ -240,6 +240,10 @@ def self.uri_encode(url)
encoded
end

def self.uri_unencode(url)
Addressable::URI.unencode(url)
end

def self.video_placeholder_html
"<div class='onebox-placeholder-container'><span class='placeholder-icon video'></span></div>"
end
Expand Down
3 changes: 2 additions & 1 deletion onebox.gemspec
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files`.split($/).reject { |s| s =~ /^(spec|web)/ }
spec.require_paths = ['lib']

spec.add_runtime_dependency 'addressable', '~> 2.7.0'
spec.add_runtime_dependency 'multi_json', '~> 1.11'
spec.add_runtime_dependency 'mustache'
spec.add_runtime_dependency 'nokogiri', '~> 1.7'
Expand All @@ -32,7 +33,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'fakeweb', '~> 1.3'
spec.add_development_dependency 'pry', '~> 0.10'
spec.add_development_dependency 'mocha', '~> 1.1'
spec.add_development_dependency 'rubocop', '~> 0.69.0'
spec.add_development_dependency 'rubocop', '~> 0.78.0'
spec.add_development_dependency 'rubocop-discourse', '~> 1.0.1'
spec.add_development_dependency 'twitter', '~> 4.8'
spec.add_development_dependency 'guard-rspec', '~> 4.2.8'
Expand Down

0 comments on commit 8ff3fff

Please sign in to comment.