diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-03-16 23:09:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-16 23:09:53 +0100 |
commit | f5daa20f2a90098c9d689c5ec9d95ce9887b3a33 (patch) | |
tree | a225407cb43edf3fa9d9ac0100021a380e11ff91 /spec/lib/plain_text_formatter_spec.rb | |
parent | 6a0ed45aa3f11f0343a7be556b36b4d075ba08df (diff) | |
parent | 32418f0ff3e7f25ca67334585d6d8442b34cb4af (diff) |
Merge pull request #2134 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'spec/lib/plain_text_formatter_spec.rb')
-rw-r--r-- | spec/lib/plain_text_formatter_spec.rb | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/spec/lib/plain_text_formatter_spec.rb b/spec/lib/plain_text_formatter_spec.rb index 4a0519aaf..80b3c331a 100644 --- a/spec/lib/plain_text_formatter_spec.rb +++ b/spec/lib/plain_text_formatter_spec.rb @@ -6,7 +6,7 @@ RSpec.describe PlainTextFormatter do describe '#to_s' do subject { described_class.new(status.text, status.local?).to_s } - context 'given a post with local status' do + context 'when status is local' do let(:status) { Fabricate(:status, text: '<p>a text by a nerd who uses an HTML tag in text</p>', uri: nil) } it 'returns the raw text' do @@ -14,12 +14,63 @@ RSpec.describe PlainTextFormatter do end end - context 'given a post with remote status' do + context 'when status is remote' do let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') } - let(:status) { Fabricate(:status, account: remote_account, text: '<p>Hello</p><script>alert("Hello")</script>') } - it 'returns tag-stripped text' do - expect(subject).to eq 'Hello' + context 'when text contains inline HTML tags' do + let(:status) { Fabricate(:status, account: remote_account, text: '<b>Lorem</b> <em>ipsum</em>') } + + it 'strips the tags' do + expect(subject).to eq 'Lorem ipsum' + end + end + + context 'when text contains <p> tags' do + let(:status) { Fabricate(:status, account: remote_account, text: '<p>Lorem</p><p>ipsum</p>') } + + it 'inserts a newline' do + expect(subject).to eq "Lorem\nipsum" + end + end + + context 'when text contains a single <br> tag' do + let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem<br>ipsum') } + + it 'inserts a newline' do + expect(subject).to eq "Lorem\nipsum" + end + end + + context 'when text contains consecutive <br> tag' do + let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem<br><br><br>ipsum') } + + it 'inserts a single newline' do + expect(subject).to eq "Lorem\nipsum" + end + end + + context 'when text contains HTML entity' do + let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem & ipsum ❤') } + + it 'unescapes the entity' do + expect(subject).to eq 'Lorem & ipsum ❤' + end + end + + context 'when text contains <script> tag' do + let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem <script> alert("Booh!") </script>ipsum') } + + it 'strips the tag and its contents' do + expect(subject).to eq 'Lorem ipsum' + end + end + + context 'when text contains an HTML comment tags' do + let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem <!-- Booh! -->ipsum') } + + it 'strips the comment' do + expect(subject).to eq 'Lorem ipsum' + end end end end |