4
Vote

carriage return added to strings ending w/ whitespace

description

GetSafeHtmlFragment("This brown fox ") = "This brown fox\r\n"
 
The added carriage return caused us some issues.

comments

AlfredC wrote Mar 2, 2011 at 6:07 PM

workaround is to call Trim() prior to GetSafeHtmlFragment()

erwin118 wrote Apr 8, 2011 at 12:02 PM

The strange think is when i do this:

Sanitizer.GetSafeHtmlFragment("1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890");

The output will be:

"1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890\r\n 1234567890"

It add a carriage return, when the text is longer it will add more carriage returns

NickPetrovits wrote Feb 15, 2012 at 11:34 PM

I am also seeing this issue, but it doesn't have to be for text that end in a white space. If the text is long enough it adds in random carriage returns everywhere.

mronnlun wrote Mar 30, 2012 at 12:13 PM

I also have the exact same problem as erwin118! It seems to add a line feed at the first space after 256 characters.

mronnlun wrote Apr 2, 2012 at 8:57 AM

The answer to the long string problem is answered here (http://stackoverflow.com/questions/9942751/asp-net-html-sanitization-library-adding-line-feed-after-256-characters). Just replace all newlines with a marker string, do the sanitation, remove all newlines that have appeared and the replace the newlinemarker with real newlines.