diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee
index ff6737bab..9d6f4c0fd 100644
--- a/app/assets/javascripts/app/lib/app_post/utils.coffee
+++ b/app/assets/javascripts/app/lib/app_post/utils.coffee
@@ -132,7 +132,6 @@ class App.Utils
# htmlOnlyWithRichtext = App.Utils.htmlRemoveRichtext(html)
@htmlRemoveRichtext: (html) ->
return html if !html
-
html = @_checkTypeOf(html)
# remove comments
@@ -156,6 +155,7 @@ class App.Utils
# cleanHtmlWithRichText = App.Utils.htmlCleanup(html)
@htmlCleanup: (html) ->
+ return html if !html
html = @_checkTypeOf(html)
# remove comments
@@ -198,7 +198,21 @@ class App.Utils
@_checkTypeOf: (item) ->
return item if typeof item isnt 'string'
- $("
#{item}
")
+
+ try
+ result = $(item)
+
+ # if we have more then on element at first level
+ if result.length > 1
+ return $("#{item}
")
+
+ # if we have just a text string without html markup
+ if !result || !result.get(0)
+ return $("#{item}
")
+
+ return result
+ catch err
+ return $("#{item}
")
@_removeAttributes: (html) ->
html.find('*')
@@ -229,6 +243,7 @@ class App.Utils
html
@_removeWordMarkup: (html) ->
+ return html if !html.get(0)
match = false
htmlTmp = html.get(0).outerHTML
regex = new RegExp('<(/w|w)\:[A-Za-z]')
diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js
index 89e7bb8a9..86066e171 100644
--- a/public/assets/tests/html_utils.js
+++ b/public/assets/tests/html_utils.js
@@ -313,7 +313,8 @@ test("htmlRemoveTags", function() {
should = "This is some text!"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
- should = "This is some text!
"
+
+ should = "This is some text!"
result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source)
@@ -403,7 +404,7 @@ test("htmlRemoveRichtext", function() {
source = "\n"
//should = "test 123
"
- should = '' + "\n"
+ should = 'Gruppe *
'
result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source)
@@ -412,7 +413,7 @@ test("htmlRemoveRichtext", function() {
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
- should = "This is some text!
"
+ should = "This is some text!"
result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source)
@@ -427,6 +428,21 @@ test("htmlCleanup", function() {
var result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
+ source = ""
+ should = "test"
+ result = App.Utils.htmlCleanup(source)
+ equal(result.html(), should, source)
+
+ source = "some link to somewhere"
+ should = "some link to somewhere"
+ result = App.Utils.htmlCleanup(source)
+ equal(result.html(), should, source)
+
+ source = "ab"
+ should = "ab"
+ result = App.Utils.htmlCleanup(source)
+ equal(result.html(), should, source)
+
source = "some link to somewhere"
should = "some link to somewhere"
result = App.Utils.htmlCleanup($(source))
@@ -503,7 +519,7 @@ test("htmlCleanup", function() {
source = "\n"
//should = "test 123
"
- should = '' + "\n"
+ should = 'Gruppe *
'
result = App.Utils.htmlCleanup(source)
equal(result.html(), should, source)