This is a migrated thread and some comments may be shown as answers.

[Solved] The 'Â' bug on saving file

1 Answer 89 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Matthew Bishop
Top achievements
Rank 1
Matthew Bishop asked on 09 Apr 2009, 05:03 AM
I came across an intresting bug that I thought I would share with everyone just incase it is happening to them as well.

When you have saved a file from the editor, if you have a tag, a space and then some text (example below), when saved the 'Â' character appears. This seems to be because a   is missing and is rather replaced with the character code 160.

<td> Some text</td> 
 
shows as:  
 
 Some text 

When you view the saved file in notepad/ word pad/ visual studio etc. you do not see the character. If you view it in a hex editor, you do.
A problem only arises if you open the saved HTML file, manipulate it and then resave it because then the character code is picked up and acted on (rendered).

Once I managed to track down the problem, the fix was really quite simple, simply:
  1. Encode the text to HTML
  2. Replace the offending character with a nbsp;
  3. Decode from HTML ready for saving or more manipulation.

 

string contentData = Server.HtmlEncode(this._RadEditor.Content);  
contentDatacontentData = contentData.Replace("&#160;", "&amp;nbsp;");  
contentData = Server.HtmlDecode(contentData); 

I must stress that this bug only appears after you try and manipulate the document by loading it, manipulating it and resaving it (but it did happen on every machine that we tested it on). If you are viewing your saved documents straight off then this should not be a problem for you.

1 Answer, 1 is accepted

Sort by
0
Lini
Telerik team
answered on 09 Apr 2009, 01:06 PM
Hello,

The #160 character (or 0xA0 in Hex) is exactly the non-breaking space. In HTML this character is  represented as &nbsp;

What happens in your case is that you open the HTML file with one encoding but save it in another (e.g. Unicode and ASCII). Make sure that you save the file without changing the encoding and you should not encounter the problem.

Kind regards,
Lini
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Matthew Bishop
Top achievements
Rank 1
Answers by
Lini
Telerik team
Share this question
or