From 3fda3a36e54bfb7e23fdadb30643542e9181c576 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 8 Nov 2026 15:59:03 +0100 Subject: [PATCH] Apply text filter when sending Note to Twitter The existing #twitter_message implementation did not apply the configured text filter. This meant that the Note as displayed in the blog itself could have a different content than the resulting tweet. --- app/models/note.rb | 2 +- spec/models/note_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/models/note.rb b/app/models/note.rb index 7178176a..a7d711d4 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -122,7 +122,7 @@ def truncate(message, length) end def twitter_message - base_message = strip_tags(body) + base_message = CGI.unescapeHTML strip_tags(html(:all)) if too_long?("#{base_message} (#{short_link})") max_length = 140 - "... (#{redirect.from_url})".length - 1 "#{truncate(base_message, max_length)}... (#{redirect.from_url})" diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 2c0e64e7..ebc7edf6 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -224,6 +224,32 @@ it { expect(note.twitter_message.length).to eq(140) } end + context "with a message containing codes interpreted by the text filter" do + let(:tweet) do + "I am **not** a crook" + end + let(:expected_tweet) do + "I am not a crook (#{note.short_link})" + end + + it "does not include the text filter codes" do + expect(note.twitter_message).to eq(expected_tweet) + end + end + + context "with a message containing literal HTML encodings" do + let(:tweet) do + "In HTML, & is encoded as `&`" + end + let(:expected_tweet) do + "In HTML, & is encoded as & (#{note.short_link})" + end + + it "contains the bare text representation of the note body" do + expect(note.twitter_message).to eq(expected_tweet) + end + end + context "don't cut word" do let(:tweet) do "Le #mobprogramming c'est un peu comme faire un dojo sur une journée entière" \