DEV: Update Rubocop and fix found issues (#418)

DEV: Update Rubocop and fix found issues (#418)

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)

diff --git a/lib/onebox/engine/amazon_onebox.rb b/lib/onebox/engine/amazon_onebox.rb
index 161a9e1..56c1726 100644
--- a/lib/onebox/engine/amazon_onebox.rb
+++ b/lib/onebox/engine/amazon_onebox.rb
@@ -15,7 +15,7 @@ module Onebox
 
       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
diff --git a/lib/onebox/engine/cloudapp_onebox.rb b/lib/onebox/engine/cloudapp_onebox.rb
index be35a7e..9f4422d 100644
--- a/lib/onebox/engine/cloudapp_onebox.rb
+++ b/lib/onebox/engine/cloudapp_onebox.rb
@@ -13,11 +13,11 @@ module Onebox
         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
 
diff --git a/lib/onebox/engine/github_blob_onebox.rb b/lib/onebox/engine/github_blob_onebox.rb
index e4c51b3..05af34e 100644
--- a/lib/onebox/engine/github_blob_onebox.rb
+++ b/lib/onebox/engine/github_blob_onebox.rb
@@ -20,7 +20,7 @@ module Onebox
         "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
diff --git a/lib/onebox/engine/gitlab_blob_onebox.rb b/lib/onebox/engine/gitlab_blob_onebox.rb
index c9cc22b..11e24c1 100644
--- a/lib/onebox/engine/gitlab_blob_onebox.rb
+++ b/lib/onebox/engine/gitlab_blob_onebox.rb
@@ -20,7 +20,7 @@ module Onebox
         "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
diff --git a/lib/onebox/helpers.rb b/lib/onebox/helpers.rb
index 9a51b38..aa38bff 100644
--- a/lib/onebox/helpers.rb
+++ b/lib/onebox/helpers.rb
@@ -1,5 +1,7 @@
 # frozen_string_literal: true
 
+require "addressable"
+
 module Onebox
   module Helpers
 
@@ -217,9 +219,7 @@ module Onebox
 
       # 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
@@ -240,6 +240,10 @@ module Onebox
       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
diff --git a/onebox.gemspec b/onebox.gemspec
index d26dac6..9b68c3b 100644
--- a/onebox.gemspec
+++ b/onebox.gemspec
@@ -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'
@@ -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'

GitHub sha: 8ff3fffd