HTML
Bitte um Freischaltung.
TEXT
end
it 'handles sample input 8' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
oh jeee … Zauberwort vergessen ;-) Können Sie mir
bitte noch meine Testphase verlängern?
HTML
oh jeee … Zauberwort vergessen ;-) Können Sie mir bitte noch meine Testphase verlängern?
TEXT
end
it 'handles sample input 9' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
HTML
TEXT
end
it 'handles sample input 10' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
| 20-29 | 200 | -1 | 201 | | | country | Target (gross) | Remaining Recruits | Total Recruits |
HTML
|
20-29 |
200 |
-1 |
201 |
|
|
country
|
Target (gross) |
Remaining Recruits |
Total Recruits |
TEXT
end
it 'handles sample input 11' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
Dear Bob:Mr/Mrs
We are one of the leading manufacturer and supplier of conduits and cars since 3000.
Could you inform me the specification you need?
May I sent you our products catalogues for your reference?
Best regards!
Welcome to our booth B11/1 Hall 13 during SOMEWHERE\n9999.
Bob Smith
Exp. & Imp.
Town Example Electric Co., Ltd.
Tel: 0000-11-12345678 (Ext-220) Fax: 0000-11-12345678
Room1234, NO. 638, Smith Road, Town, 200000, Somewhere
Web: www.example.com
HTML
\n
Dear Bob:Mr/Mrs
We are one of the leading manufacturer and supplier of conduits and cars since 3000.
Could you inform me the specification you need?
May I sent you our products catalogues for your reference?
Best regards!
Welcome to our booth B11/1 Hall 13 during SOMEWHERE 9999.
\n
Bob Smith
\n
Exp. & Imp.
Town Example Electric Co., Ltd.
Tel: 0000-11-12345678 (Ext-220) Fax: 0000-11-12345678
Room1234, NO. 638, Smith Road, Town, 200000, Somewhere
Web: www.example.com
TEXT
end
it 'handles sample input 12' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
Luxemburg
HTML
Luxemburg
TEXT
end
# https://github.com/zammad/zammad/issues/4112
it 'converts lists from MS Outlook correctly' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
·
1
·
2
HTML
• 1
• 2
TEXT
end
# https://github.com/zammad/zammad/issues/4184
it 'deletes downlevel revealed conditional comments' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
dummy1
dummy2
HTML
dummy1 dummy2
TEXT
end
end
context 'signature recognition' do
let(:marker) { '' }
it 'does not trim trailing whitespace and keeps the signature block working' do
expect('Hello
--
This is the signature'.html2html_strict.first).to eq("Hello
#{marker}
--
This is the signature")
end
it 'places marker before "--" line (surrounded by
)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
lalala
--
Max Mix
HTML
lalala#{marker}
--
Max Mix
TEXT
end
it 'places marker before "--" line (surrounded by
)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
lalala
--
Max Mix
HTML
lalala#{marker}
--
Max Mix
TEXT
end
it 'places marker before "--" line (preceded by
\n)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
lalala
--
Max Mix
HTML
lalala#{marker}
--
Max Mix
TEXT
end
it 'places marker before "--" line (surrounded by
)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
lalala
--
Max Mix
HTML
lalala#{marker}
--
Max Mix
TEXT
end
it 'places marker before "__" line (surrounded by
)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
lalala
__
Max Mix
HTML
lalala#{marker}
__
Max Mix
TEXT
end
it 'places marker before quoted reply’s "Von:" header (in German)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
den.
Von: Fritz Bauer [mailto:me@example.com]
Gesendet: Donnerstag, 3. Mai 2012 11:51
An: John Smith
Cc: Smith, John Marian; johnel.fratczak@example.com; ole.brei@example.com; Günther John | Example GmbH; bkopon@example.com; john.heisterhagen@team.example.com; sven.rocked@example.com; michael.house@example.com; tgutzeit@example.com
Betreff: Re: OTRS::XXX Erweiterung - Anhänge an CI's
Hello,
ich versuche an den Punkten
HTML
den.
#{marker}
Von: Fritz Bauer [mailto:me@example.com]
Gesendet: Donnerstag, 3. Mai 2012 11:51
An: John Smith
Cc: Smith, John Marian; johnel.fratczak@example.com; ole.brei@example.com; Günther John | Example GmbH; bkopon@example.com; john.heisterhagen@team.example.com; sven.rocked@example.com; michael.house@example.com; tgutzeit@example.com
Betreff: Re: OTRS::XXX Erweiterung - Anhänge an CI's
Hello,
ich versuche an den Punkten
TEXT
end
it 'places marker before quoted reply’s "Von:" header (as
with stripped parent
)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
Von: Martin Edenhofer via Zammad Helpdesk [mailto:support@zammad.com]
Gesendet:\u0020
HTML
TEXT
end
it 'places marker before quoted reply’s "Von:" header (as with parent
)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
Von:
Johanna Kiefer via Zammad Projects <projects@example.com>
Organisation: Zammad GmbH
Datum: Montag, 6. März 2017 um 13:32
HTML
#{marker}
Von: Johanna Kiefer via Zammad Projects <projects@example.com>
Organisation: Zammad GmbH
Datum: Montag, 6. März 2017 um 13:32
TEXT
end
it 'places marker before quoted reply’s "Von:" header (as )' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
Von:
Hotel <info@example.com>
An:
HTML
#{marker}
Von: Hotel <info@example.com>
An:
TEXT
end
it 'places marker before English quoted text intro (as
)' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
HTML
TEXT
end
it 'does not place marker if blockquote doesn’t contain a quoted text intro' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
some note
HTML
TEXT
end
it 'does not place marker if quoted text intro isn’t followed by a ' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
Am 17.03.2017 um 17:03 schrieb Martin Edenhofer via Zammad Helpdesk <support@example.com>:
HTML
Am 17.03.2017 um 17:03 schrieb Martin Edenhofer via Zammad Helpdesk <support@example.com>:
TEXT
end
it 'places marker before German quoted text intro (before )' do
expect(<<~HTML.chomp.html2html_strict.first).to eq(<<~TEXT.chomp)
Am 17.03.2017 um 17:03 schrieb Martin Edenhofer via Zammad Helpdesk <support@example.com>:
Dear Mr. Smith,
HTML
#{marker}
Am 17.03.2017 um 17:03 schrieb Martin Edenhofer via Zammad Helpdesk <support@example.com>:
Dear Mr. Smith,
TEXT
end
end
end
describe '#signature_identify' do
let(:marker) { '######SIGNATURE_MARKER######' }
context 'with no signature present' do
it 'leaves string as-is' do
expect((+'foo').signature_identify('text', true)).to eq('foo')
end
end
context 'with signature present' do
it 'places marker at start of "--" line' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
foo
--
bar
SRC
foo
#{marker}--
bar
MARKED
end
it 'places marker before English quoted text intro' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
On 01/04/15 10:55, Bob Smith wrote:
SRC
#{marker}On 01/04/15 10:55, Bob Smith wrote:
MARKED
end
it 'places marker before German quoted text intro' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
Am 03.04.2015 um 20:58 schrieb Martin Edenhofer :
SRC
#{marker}Am 03.04.2015 um 20:58 schrieb Martin Edenhofer :
MARKED
end
it 'ignores trailing empty line' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123
test 123
--
Bob Smith
SRC
test 123
test 123
#{marker}--
Bob Smith
MARKED
end
it 'ignores trailing double empty lines' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123
test 123
--
Bob Smith
SRC
test 123
test 123
#{marker}--
Bob Smith
MARKED
end
it 'ignores leading/trailing empty lines' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123\u0020
1
2
3
4
5
6
7
8
9
--
Bob Smith
SRC
test 123\u0020
1
2
3
4
5
6
7
8
9
#{marker}--
Bob Smith
MARKED
end
it 'ignores lines starting with "--" but containing more text' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123\u0020
--no not match--
--
Bob Smith
SRC
test 123\u0020
--no not match--
#{marker}--
Bob Smith
MARKED
end
it 'places marker at start of " -- " line' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123\u0020
--no not match--
--\u0020
Bob Smith
SRC
test 123\u0020
--no not match--
#{marker} --\u0020
Bob Smith
MARKED
end
it 'places marker on empty line if possible / only places one marker' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123\u0020
--
Bob Smith
--
Bob Smith
SRC
test 123\u0020
#{marker}
--
Bob Smith
--
Bob Smith
MARKED
end
context 'for Apple email quote text' do
context 'in English' do
it 'places two markers, one before quoted text intro and one at start of "--" line' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123\u0020
--no not match--
Bob Smith
On 01/04/15 10:55, Bob Smith wrote:
lalala
--
some test
SRC
test 123\u0020
--no not match--
Bob Smith
#{marker}On 01/04/15 10:55, Bob Smith wrote:
lalala
#{marker}--
some test
MARKED
end
end
context 'auf Deutsch' do
it 'places marker before quoted text intro' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123\u0020
--no not match--
Bob Smith
Am 03.04.2015 um 20:58 schrieb Bob Smith :
lalala
SRC
test 123\u0020
--no not match--
Bob Smith
#{marker}Am 03.04.2015 um 20:58 schrieb Bob Smith :
lalala
MARKED
end
end
end
context 'for MS email quote text' do
context 'in English' do
it 'places marker before quoted text intro' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123test 123\u0020
--no not match--
Bob Smith
From: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
Sent: Donnerstag, 2. April 2015 10:00
lalala
SRC
test 123test 123\u0020
--no not match--
Bob Smith
#{marker}From: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
Sent: Donnerstag, 2. April 2015 10:00
lalala
MARKED
end
end
context 'auf Deutsch' do
it 'places marker before quoted text intro' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123\u0020
--no not match--
Bob Smith
Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
Gesendet: Donnerstag, 2. April 2015 10:00
Betreff: lalala
SRC
test 123\u0020
--no not match--
Bob Smith
#{marker}Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
Gesendet: Donnerstag, 2. April 2015 10:00
Betreff: lalala
MARKED
end
end
context 'en francais' do
it 'places marker before quoted text intro' do
expect(<<~SRC.chomp.signature_identify('text', true)).to eq(<<~MARKED.chomp)
test 123\u0020
--no not match--
Bob Smith
De : Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
Envoyé : mercredi 29 avril 2015 17:31
Objet : lalala
SRC
test 123\u0020
--no not match--
Bob Smith
#{marker}De : Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
Envoyé : mercredi 29 avril 2015 17:31
Objet : lalala
MARKED
end
end
end
end
end
describe '#utf8_encode' do
context 'on valid, UTF-8-encoded strings' do
subject(:string) { 'hello' }
it 'returns an identical copy' do
expect(string.utf8_encode).to eq(string)
expect(string.utf8_encode.encoding).to be(string.encoding)
expect(string.utf8_encode).not_to be(string)
end
context 'which are incorrectly set to other, technically valid encodings' do
subject(:string) { described_class.new('ö', encoding: 'tis-620') }
it 'sets input encoding to UTF-8 instead of attempting conversion' do
expect(string.utf8_encode).to eq(string.dup.force_encoding('utf-8'))
end
end
end
context 'on strings in other encodings' do
subject(:string) { original_string.encode(input_encoding) }
context 'with no from: option' do
let(:original_string) { 'Tschüss!' }
let(:input_encoding) { Encoding::ISO_8859_2 }
it 'detects the input encoding' do
expect(string.utf8_encode).to eq(original_string)
end
end
context 'with a valid from: option' do
let(:original_string) { 'Tschüss!' }
let(:input_encoding) { Encoding::ISO_8859_2 }
it 'uses the specified input encoding' do
expect(string.utf8_encode(from: 'iso-8859-2')).to eq(original_string)
end
it 'uses any valid input encoding, even if not correct' do
expect(string.utf8_encode(from: 'gb18030')).to eq('Tsch黶s!')
end
end
context 'with an invalid from: option' do
let(:original_string) { '―陈志' }
let(:input_encoding) { Encoding::GB18030 }
it 'does not try it' do
expect { string.encode('utf-8', 'gb2312') }
.to raise_error(Encoding::InvalidByteSequenceError)
expect { string.utf8_encode(from: 'gb2312') }
.not_to raise_error
end
it 'uses the detected input encoding instead' do
expect(string.utf8_encode(from: 'gb2312')).to eq(original_string)
end
end
end
context 'performance' do
subject(:string) { original_string.encode(input_encoding) }
context 'with utf8_encode in iso-8859-1' do
let(:original_string) { 'äöü0' * 999_999 }
let(:input_encoding) { Encoding::ISO_8859_1 }
it 'detects the input encoding' do
Timeout.timeout(1) do
expect(string.utf8_encode(from: 'iso-8859-1')).to eq(original_string)
end
end
end
context 'with utf8_encode in utf-8' do
let(:original_string) { 'äöü0' * 999_999 }
let(:input_encoding) { Encoding::UTF_8 }
it 'detects the input encoding' do
Timeout.timeout(1) do
expect(string.utf8_encode(from: 'utf-8')).to eq(original_string)
end
end
end
context 'with utf8_encode in iso-8859-1 and charset detection' do
let(:original_string) { 'äöü0' * 199_999 }
let(:input_encoding) { Encoding::ISO_8859_1 }
it 'detects the input encoding' do
Timeout.timeout(18) do
expect(string.utf8_encode(from: 'utf-8')).to eq(original_string)
end
end
end
end
end
end