diff --git a/lib/onebox/engine/gfycat_onebox.rb b/lib/onebox/engine/gfycat_onebox.rb index 44ca947f66f..291665414d5 100644 --- a/lib/onebox/engine/gfycat_onebox.rb +++ b/lib/onebox/engine/gfycat_onebox.rb @@ -76,7 +76,7 @@ module Onebox script = page.at_css('script[type="application/ld+json"]') if json_string = script&.text - @og_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(json_string)) + @og_data = ::MultiJson.load(json_string, symbolize_keys: true) else @og_data = {} end diff --git a/lib/onebox/engine/imgur_onebox.rb b/lib/onebox/engine/imgur_onebox.rb index 127f73baee9..c1e6efb2bd3 100644 --- a/lib/onebox/engine/imgur_onebox.rb +++ b/lib/onebox/engine/imgur_onebox.rb @@ -53,7 +53,7 @@ module Onebox rescue StandardError "{}" end - oembed_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(response)) + oembed_data = ::MultiJson.load(response, symbolize_keys: true) imgur_data_id = Nokogiri.HTML(oembed_data[:html]).xpath("//blockquote").attr("data-id") imgur_data_id.to_s[%r{a/}] end diff --git a/lib/onebox/engine/vimeo_onebox.rb b/lib/onebox/engine/vimeo_onebox.rb index 4a684641e46..a5e1aace98c 100644 --- a/lib/onebox/engine/vimeo_onebox.rb +++ b/lib/onebox/engine/vimeo_onebox.rb @@ -34,7 +34,7 @@ module Onebox def oembed_data response = Onebox::Helpers.fetch_response("https://vimeo.com/api/oembed.json?url=#{url}") - @oembed_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(response)) + @oembed_data = ::MultiJson.load(response, symbolize_keys: true) rescue StandardError "{}" end diff --git a/lib/onebox/helpers.rb b/lib/onebox/helpers.rb index 108af6d0260..3d2ee7013a0 100644 --- a/lib/onebox/helpers.rb +++ b/lib/onebox/helpers.rb @@ -9,17 +9,6 @@ module Onebox IGNORE_CANONICAL_DOMAINS ||= %w[www.instagram.com medium.com youtube.com] - def self.symbolize_keys(hash) - return {} if hash.nil? - - hash.inject({}) do |result, (key, value)| - new_key = key.is_a?(String) ? key.to_sym : key - new_value = value.is_a?(Hash) ? symbolize_keys(value) : value - result[new_key] = new_value - result - end - end - def self.clean(html) html.gsub(/<[^>]+>/, " ").gsub(/\n/, "") end diff --git a/lib/onebox/layout.rb b/lib/onebox/layout.rb index 53c63bb834f..69c03842e50 100644 --- a/lib/onebox/layout.rb +++ b/lib/onebox/layout.rb @@ -12,7 +12,7 @@ module Onebox attr_reader :view def initialize(name, record) - @record = Onebox::Helpers.symbolize_keys(record) + @record = record.deep_symbolize_keys # Fix any relative paths if @record[:image] && @record[:image] =~ %r{\A/[^/]} diff --git a/lib/onebox/oembed.rb b/lib/onebox/oembed.rb index d5c2bd20aa4..85d0dae506b 100644 --- a/lib/onebox/oembed.rb +++ b/lib/onebox/oembed.rb @@ -3,7 +3,7 @@ module Onebox class Oembed < OpenGraph def initialize(response) - @data = Onebox::Helpers.symbolize_keys(::MultiJson.load(response)) + @data = ::MultiJson.load(response, symbolize_keys: true) # never use oembed from WordPress 4.4 (it's broken) @data.delete(:html) if @data[:html] && @data[:html]["wp-embedded-content"] diff --git a/spec/lib/onebox/engine/google_maps_onebox_spec.rb b/spec/lib/onebox/engine/google_maps_onebox_spec.rb index fab528a6799..1a6fc66f36a 100644 --- a/spec/lib/onebox/engine/google_maps_onebox_spec.rb +++ b/spec/lib/onebox/engine/google_maps_onebox_spec.rb @@ -72,7 +72,7 @@ RSpec.describe Onebox::Engine::GoogleMapsOnebox do end end - let(:data) { Onebox::Helpers.symbolize_keys(onebox.send(:data)) } + let(:data) { onebox.send(:data).deep_symbolize_keys } let(:link) { |example| URLS[example.metadata[:urltype] || :short][:test] } include_context "an engine", urltype: :short diff --git a/spec/support/onebox_helpers.rb b/spec/support/onebox_helpers.rb index 867de71e5c6..9d8955e64fc 100644 --- a/spec/support/onebox_helpers.rb +++ b/spec/support/onebox_helpers.rb @@ -22,7 +22,7 @@ module OneboxHelpers let(:onebox) { described_class.new(link) } let(:html) { onebox.to_html } - let(:data) { Onebox::Helpers.symbolize_keys(onebox.send(:data)) } + let(:data) { onebox.send(:data).deep_symbolize_keys } let(:link) { @link } end