Commit Graph

19 Commits

Author SHA1 Message Date
erikarenhill
b363a1711a U4-10478: Bugfix where it would throw an IndexOutOfBounds when passing a word shorter than … to Truncate. Now checks whether the input wanted an elipsis and also if it reached the end. 2017-09-28 15:52:13 +02:00
Shannon Deminick
41eeb38c5f Merge pull request #2043 from umbraco/TEMP-u4-10135
Added TruncateByWords method + overloads
2017-09-12 13:36:00 +10:00
Claus
733c920867 using string.replace instead of regex.
adding unit test.
2017-09-08 13:57:28 +02:00
Robert
18d0fec014 Added some trimming and test to StripHtmlTags 2017-09-06 12:03:15 +02:00
Robert
b2798e38f7 Replaced html stripping with already existing function, removing unused code 2017-09-06 11:12:14 +02:00
Shannon
a603fd0c46 Merge branch 'TEMP-u4-10135' of https://github.com/umbraco/Umbraco-CMS into TEMP-u4-10135
# Conflicts:
#	src/Umbraco.Web/HtmlStringUtilities.cs
2017-09-06 10:05:00 +10:00
Shannon
4b5c49907c switches to constant - comments out what seems to be a totally unused variable 2017-09-06 10:01:39 +10:00
Robert
972d5f8296 Reverted back to last commit, invalid html check added 2017-09-03 21:17:53 +02:00
Robert
73937172dc Added check for invalid HTML and sanitization on said HTML
Added HtmlSanitization package
Added check for invalid HTML and sanitization on WordsToLength and Truncate methods
Addes some extra comments
2017-08-31 11:43:06 +02:00
Robert
8c1996a7a1 Changed from the String object qualifier to type qualifier 2017-08-31 09:15:02 +02:00
Robert
039ab8f1d2 Null check for firstTrim added and fixed typo 2017-08-30 09:18:45 +02:00
Robert
68fd74897f Replaced the Regex parse with HtmlAgilityPack parser 2017-08-28 10:52:53 +02:00
Robert
047a41c05e Having a space in a tag is now taken as a char length and not as a space between words 2017-08-28 10:14:16 +02:00
Robert
84f684ed31 Truncate with trimming should now work, added some mpore tests for truncate by words methods
Fix: Original Truncate method show now be able to trim
Add: Added some more tests for Truncate by words to cater for tagsAsContent parameter
Fix: In original truncate, currentTextLength prop will be increased everytime a tag is added, this will fix an issue when tagsAsContent is set to true (it would have added an extra char per tag, which would have went over to the next word)
2017-08-25 11:39:13 +02:00
Robert
54f86c06f0 Fix TruncateByWords to work with tags 2017-08-21 12:30:16 +02:00
Harvey Williams
13f76d2af9 Updated ReplaceLineBreaksForHtml to include \r
I was surprised when this method did not replace a `\r` character with an HTML break. I have updated it to not only replace `\n`, but also `\r\n` and just `\r`.

I think these cases should be considered because of [this SO thread](https://stackoverflow.com/questions/4824621/is-a-new-line-n-or-r-n).

The updated code will not replace `\n\r` with one break but with two.

I used [this SO answer](https://stackoverflow.com/a/8196219/2963111) to update the method.

```
[TestMethod]
public void ReplaceLineBreaksForHtmlTest()
{
    var result = "foo\rbar\nbaz\r\nbiff\n\r".ReplaceLineBreaksForHtml();

    Assert.AreEqual(result, "foo<br />\rbar<br />\nbaz<br />\r\nbiff<br />\n<br />\r");
}
```
2017-08-11 11:42:35 +01:00
Robert
769f0d97d2 Added TruncateByWords method + overloads 2017-07-12 10:35:09 +02:00
Lotte Pitcher
c8b23195f6 When truncating if the last characters was the first half of a two word unicode character, also include the second half to avoid YSOD 2016-11-03 14:30:38 +00:00
Shannon
c760a7c50d Merge branch 'dev-v7-7.3.0-UmbHelperInterfaces' of https://github.com/Shazwazza/Umbraco-CMS into Shazwazza-dev-v7-7.3.0-UmbHelperInterfaces
Conflicts:
	src/Umbraco.Web/Umbraco.Web.csproj
2015-02-18 17:14:55 +01:00