diff --git a/Changelog.md b/Changelog.md index 23417422f..159c3c160 100644 --- a/Changelog.md +++ b/Changelog.md @@ -44,6 +44,7 @@ The default for including jQuery from a CDN has changed. If you want to continue ## Bug fixes * orca cannot see 'Add Contact' button [#5158](https://github.com/diaspora/diaspora/pull/5158) * Move submit button to the right in conversations view [#4960](https://github.com/diaspora/diaspora/pull/4960) +* Handle long URLs and titles in OpenGraph descriptions [#5208](https://github.com/diaspora/diaspora/pull/5208) ## Features * Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105) diff --git a/app/models/open_graph_cache.rb b/app/models/open_graph_cache.rb index 8c6e32841..d0c94362e 100644 --- a/app/models/open_graph_cache.rb +++ b/app/models/open_graph_cache.rb @@ -26,7 +26,7 @@ class OpenGraphCache < ActiveRecord::Base return if response.blank? || response.type.blank? - self.title = response.title + self.title = response.title.truncate(255) self.ob_type = response.type self.image = response.images[0] self.url = response.url diff --git a/db/migrate/20140906192846_fix_open_graph_data.rb b/db/migrate/20140906192846_fix_open_graph_data.rb new file mode 100644 index 000000000..54959931d --- /dev/null +++ b/db/migrate/20140906192846_fix_open_graph_data.rb @@ -0,0 +1,10 @@ +class FixOpenGraphData < ActiveRecord::Migration + def self.up + change_column :open_graph_caches, :url, :text + change_column :open_graph_caches, :image, :text + end + def self.down + change_column :open_graph_caches, :url, :string + change_column :open_graph_caches, :image, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index aa8406d86..80202933c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140826165533) do +ActiveRecord::Schema.define(version: 20140906192846) do create_table "account_deletions", force: true do |t| t.string "diaspora_handle" @@ -219,8 +219,8 @@ ActiveRecord::Schema.define(version: 20140826165533) do create_table "open_graph_caches", force: true do |t| t.string "title" t.string "ob_type" - t.string "image" - t.string "url" + t.text "image" + t.text "url" t.text "description" end @@ -570,4 +570,4 @@ ActiveRecord::Schema.define(version: 20140826165533) do add_foreign_key "share_visibilities", "contacts", name: "post_visibilities_contact_id_fk", dependent: :delete -end +end \ No newline at end of file diff --git a/spec/workers/gather_open_graph_data_spec.rb b/spec/workers/gather_open_graph_data_spec.rb index 7c2397e4f..3416047c4 100644 --- a/spec/workers/gather_open_graph_data_spec.rb +++ b/spec/workers/gather_open_graph_data_spec.rb @@ -16,12 +16,25 @@ describe Workers::GatherOpenGraphData do " + @oglong_title = "D" * 256 + @oglong_url = 'http://www.we-are-too-long.com' + @oglong_body = + "#{@oglong_title} + + + + + + " + @no_open_graph_url = 'http://www.we-do-not-support-open-graph.com/index.html' @status_message = FactoryGirl.create(:status_message) stub_request(:get, @ogsite_url).to_return(:status => 200, :body => @ogsite_body) stub_request(:get, @no_open_graph_url).to_return(:status => 200, :body => 'hello there') + stub_request(:get, @oglong_url).to_return(:status => 200, :body => @oglong_body) + end describe '.perform' do @@ -65,5 +78,11 @@ describe Workers::GatherOpenGraphData do Workers::GatherOpenGraphData.new.perform(0, @ogsite_url) }.to_not raise_error end + it 'truncates + inserts titles that are too long' do + Workers::GatherOpenGraphData.new.perform(@status_message.id, @oglong_url) + ogc = OpenGraphCache.find_by_url(@oglong_url) + expect(ogc).to be_truthy + expect(ogc.title.length).to be <= 255 + end end end