diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index b060d80bb..b46611edc 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -103,6 +103,9 @@ class String # remove style tags with content string.gsub!( %r{(.+?)}im, '') + # insert spaces on [A-z]\n[A-z] + string.gsub!( /([A-z])\n([A-z])/m, '\1 \2' ) + # remove empty lines string.gsub!( /^\s*/m, '' ) diff --git a/test/unit/aaa_string_test.rb b/test/unit/aaa_string_test.rb index 2f69834d1..c533c71aa 100644 --- a/test/unit/aaa_string_test.rb +++ b/test/unit/aaa_string_test.rb @@ -7,123 +7,127 @@ class AaaStringTest < ActiveSupport::TestCase modul = 'test' result = 'test' modul.to_filename - assert_equal( result, modul ) + assert_equal(result, modul) modul = 'Some::File' result = 'Some::File' modul.to_filename - assert_equal( result, modul ) + assert_equal(result, modul) end test 'to_filename function' do modul = 'test' result = 'test' - assert_equal( result, modul.to_filename ) + assert_equal(result, modul.to_filename) modul = 'Some::File' result = 'some/file' - assert_equal( result, modul.to_filename ) + assert_equal(result, modul.to_filename) end test 'to_classname ref' do modul = 'test' result = 'test' modul.to_filename - assert_equal( result, modul ) + assert_equal(result, modul) modul = 'some/file' result = 'some/file' modul.to_filename - assert_equal( result, modul ) + assert_equal(result, modul) end test 'to_classname function' do modul = 'test' result = 'Test' - assert_equal( result, modul.to_classname ) + assert_equal(result, modul.to_classname) modul = 'some/file' result = 'Some::File' - assert_equal( result, modul.to_classname ) + assert_equal(result, modul.to_classname) modul = 'some/files' result = 'Some::Files' - assert_equal( result, modul.to_classname ) + assert_equal(result, modul.to_classname) modul = 'some_test/files' result = 'SomeTest::Files' - assert_equal( result, modul.to_classname ) + assert_equal(result, modul.to_classname) end test 'html2text ref' do html = 'test' result = 'test' html.html2text - assert_equal( result, html ) + assert_equal(result, html) html = '
test
' result = '
test
' html.html2text - assert_equal( result, html ) + assert_equal(result, html) end test 'html2text function' do html = 'test' result = 'test' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = ' test ' result = 'test' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "\n\n test \n\n\n" result = 'test' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = '
test
' result = 'test' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = '
test
' result = 'test' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "
test


\n
\n
\n
" result = 'test' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "
test\n\ntest
" result = "test\ntest" - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "test\n\ntest" result = "test\ntest" - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = '
testcol
test4711
' result = "test col \ntest 4711" - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) + + html = "

Was\nsoll verbessert werden:

" + result = 'Was soll verbessert werden:' + assert_equal(result, html.html2text) html = "
test


\n
\n
\n
" result = 'test' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "\n
Best Tool of the World some other text
" result = "[1] Best Tool of the Worldsome other text\n\n\n[1] http://zammad.org" - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "
test


\n
\n
\n
" result = "test\n\n___" - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = ' line 1
you
@@ -131,12 +135,12 @@ you
should = 'line 1 you -----&' - assert_equal( should, html.html2text ) + assert_equal( should, html.html2text) html = ' ' should = '* #1 * #2' - assert_equal( should, html.html2text ) + assert_equal( should, html.html2text) html = ' @@ -151,7 +155,7 @@ you > > Thank you for installing Zammad. >' - assert_equal( should, html.html2text ) + assert_equal( should, html.html2text) html = '

some other content

' should = 'some other content' - assert_equal( should, html.html2text ) + assert_equal( should, html.html2text) html = ' IT-Infrastruktur
@@ -253,7 +257,7 @@ div.wordsection1 ' should = 'IT-Infrastruktur' - assert_equal( should, html.html2text ) + assert_equal( should, html.html2text) html = "

some head

some content @@ -268,7 +272,7 @@ some content > line 2 some text later' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "

some head

some content @@ -283,7 +287,7 @@ some content > line 2 some text later' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "

some head

some content @@ -298,7 +302,7 @@ some content > > line 2 some text later' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "

Best regards,

Your Team Team

@@ -312,7 +316,7 @@ P.S.: You receive this e-mail because you are listed in our database as person w [1] http://www.teamviewer.example/en/company/unsubscribe.aspx?id=1009645&ident=xxx' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) html = "

Dave and leaned her days adam.
Maybe we @@ -325,7 +329,7 @@ Maybe we want any help me that. Next morning charlie saw at their father. Well as though adam took out here. Melvin will be more money. Called him into this one last thing. Men-----------------------' - assert_equal( result, html.html2text ) + assert_equal(result, html.html2text) end