diff --git a/src/Umbraco.Tests/FrontEnd/UmbracoHelperTests.cs b/src/Umbraco.Tests/FrontEnd/UmbracoHelperTests.cs
index d886009e00..1e808ab8b2 100644
--- a/src/Umbraco.Tests/FrontEnd/UmbracoHelperTests.cs
+++ b/src/Umbraco.Tests/FrontEnd/UmbracoHelperTests.cs
@@ -95,37 +95,72 @@ namespace Umbraco.Tests.FrontEnd
}
[Test]
- public void Truncate_By_Words()
+ public void Truncate_By_Words_TagsAsContentOff()
{
var text = "Hello world, this is some text with a link";
var helper = new UmbracoHelper();
- var result = helper.TruncateByWords(text, 4).ToString();
+ var result = helper.TruncateByWords(text, 4, true, false).ToString();
Assert.AreEqual("Hello world, this is…", result);
}
[Test]
- public void Truncate_By_Words_With_Tag()
+ public void Truncate_By_Words_With_Tag_TagsAsContentOff()
{
var text = "Hello world, this is some text with a link";
var helper = new UmbracoHelper();
- var result = helper.TruncateByWords(text, 4).ToString();
+ var result = helper.TruncateByWords(text, 4, true, false).ToString();
Assert.AreEqual("Hello world, this is…", result);
}
[Test]
- public void Truncate_By_Words_Mid_Tag()
+ public void Truncate_By_Words_Mid_Tag_TagsAsContentOff()
{
var text = "Hello world, this is some text with a link";
var helper = new UmbracoHelper();
- var result = helper.TruncateByWords(text, 7).ToString();
+ var result = helper.TruncateByWords(text, 7, true, false).ToString();
+
+ Assert.AreEqual("Hello world, this is some text with…", result);
+ }
+ [Test]
+ public void Truncate_By_Words_TagsAsContentOn()
+ {
+ var text = "Hello world, this is some text with a link";
+
+ var helper = new UmbracoHelper();
+
+ var result = helper.TruncateByWords(text, 4, true, true).ToString();
+
+ Assert.AreEqual("Hello world, this is…", result);
+ }
+
+ [Test]
+ public void Truncate_By_Words_With_Tag_TagsAsContentOn()
+ {
+ var text = "Hello world, this is some text with a link";
+
+ var helper = new UmbracoHelper();
+
+ var result = helper.TruncateByWords(text, 4, true, true).ToString();
+
+ Assert.AreEqual("Hello world, this is…", result);
+ }
+
+ [Test]
+ public void Truncate_By_Words_Mid_Tag_TagsAsContentOn()
+ {
+ var text = "Hello world, this is some text with a link";
+
+ var helper = new UmbracoHelper();
+
+ var result = helper.TruncateByWords(text, 7, true, true).ToString();
Assert.AreEqual("Hello world, this is some text with…", result);
}
diff --git a/src/Umbraco.Web/HtmlStringUtilities.cs b/src/Umbraco.Web/HtmlStringUtilities.cs
index 08e73e389d..166ba44667 100644
--- a/src/Umbraco.Web/HtmlStringUtilities.cs
+++ b/src/Umbraco.Web/HtmlStringUtilities.cs
@@ -6,6 +6,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using HtmlAgilityPack;
+using Umbraco.Web.WebApi.Filters;
namespace Umbraco.Web
{
@@ -142,6 +143,10 @@ namespace Umbraco.Web
{
string thisTag = tagStack.Pop();
outputtw.Write("" + thisTag + ">");
+ if (treatTagsAsContent)
+ {
+ currentTextLength++;
+ }
}
if (!isTagClose && currentTag.Length > 0)
{
@@ -149,6 +154,10 @@ namespace Umbraco.Web
{
tagStack.Push(currentTag);
outputtw.Write("<" + currentTag);
+ if (treatTagsAsContent)
+ {
+ currentTextLength++;
+ }
if (!string.IsNullOrEmpty(tagContents))
{
if (tagContents.EndsWith("/"))
@@ -236,7 +245,14 @@ namespace Umbraco.Web
outputms.Position = 0;
using (TextReader outputtr = new StreamReader(outputms))
{
- return new HtmlString(outputtr.ReadToEnd().Replace(" ", " ").Trim());
+ string result = String.Empty;
+
+ string firsTrim = outputtr.ReadToEnd().Replace(" ", " ").Trim();
+
+ //Check to see if there is an empty char between the hellip and the output string
+ //if there is, remove it
+ result = firsTrim[firsTrim.Length -9] == ' ' ? firsTrim.Remove(firsTrim.Length - 9, 1) : firsTrim;
+ return new HtmlString(result);
}
}
}