Rad rich textbox Html Binding is not working when specific characters found in data

1 Answer 31 Views
RichTextBox
Kamran
Top achievements
Rank 3
Iron
Veteran
Iron
Kamran asked on 14 Jan 2022, 08:10 PM

I am pasting text which contains invalid characters (example utf8 hex FFFE). Html binding is not workin in this case. I reproduced binding issue in Telerik wpf demo. Where xaml binding is working fine, while html binding is empty.

For reference I am pasting following text into Richtext box editor. which is bound to HTML binder.

registration received from the office of Sub￾Registrar/ Joint Sub-Registrar and online
I have attached Rich text box behavior and also specific character details.  

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 19 Jan 2022, 03:47 PM

Hello Kamran,

Thank you for the detailed information. I have confirmed that this is an issue in RadRichTextBox and logged a report for it: RichTextBox: InvalidOperationException thrown when trying to export HTML with invalid characters. Please, make sure to subscribe to this task so you can be notified when its status changes. A possible approach for working around the error that is thrown internally is to remove the symbol from the content.

Your Telerik points are updated in appreciation of this report.

Hope this information is helpful.

Regards,
Tanya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Kamran
Top achievements
Rank 3
Iron
Veteran
Iron
commented on 19 Jan 2022, 04:54 PM | edited

Hi Tanya,

Thanks for your support.

Currently I have handled above issue in command executing event. Please if you can review following code.

Just to update. Following code is working fine for English text, but when I am pasting Arabic/ Urdu (Text from Right to left) raise exception (catch block) and final content is not correct.


Actual Text:
تیز رفتار انٹرنیٹ اور وسیع تر کوریج فراہم کرنے والی اس سی بینڈ سروس کو ایک دن بعد شروع کیا جانا تھا۔

After paste.
ی فا نری و سع ر وی رہ رے ای س ی یڈ رس و ی ن ع رع ی اا ھ۔


 private void editor_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
        {
            if(e.Command is PasteCommand)
            {
                e.Cancel = true;
                bool deleted = false;
                RadDocument document = ClipboardEx.GetDocument().ToDocument();
                DocumentTextSearch search = new DocumentTextSearch(document);
                List<TextRange> rangesTrackingDocumentChanges = new List<TextRange>();


                foreach (var textRange in search.FindAll(@"[^\u0000-\u03E7]"))
                {
                    if (textRange == null) continue;
                    TextRange newRange = new TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
                    rangesTrackingDocumentChanges.Add(newRange);
                }

                RadDocumentEditor docEdit;
                foreach (var textRange in rangesTrackingDocumentChanges)
                {
                    try
                    {
                        document.CaretPosition.MoveToPosition(textRange.StartPosition);

                        document.Selection.AddSelectionStart(textRange.StartPosition);
                        document.Selection.AddSelectionEnd(textRange.EndPosition);
                        docEdit = new RadDocumentEditor(document);
                        docEdit.Delete(deleted);
                        document.Selection.Clear();
                        docEdit.Insert("");
                        textRange.StartPosition.Dispose();
                        textRange.EndPosition.Dispose();
                    }
                    catch
                    {
                       
                    }
                }

                this.editor.InsertFragment(new DocumentFragment(document));

            }
        }

Tanya
Telerik team
commented on 21 Jan 2022, 05:17 PM

Hello Kamran,

I would suggest you track the single symbol only. Otherwise, there is the possibility to match more symbols than needed, as in the case with Arabic. Here is how I have modified your code:

// Match a single symbol
foreach (var textRange in search.FindAll("\ufffe"))
{
    if (textRange == null) continue;
    TextRange newRange = new TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
    rangesTrackingDocumentChanges.Add(newRange);
}

RadDocumentEditor docEdit;
foreach (var textRange in rangesTrackingDocumentChanges)
{
    try
    {
        // Each match would be a single symbol according to the Regex we used
        document.CaretPosition.MoveToPosition(textRange.StartPosition);
        docEdit = new RadDocumentEditor(document);
        docEdit.Delete(deleted);
    }
    catch
    {

    }
}

Hope this helps.

Tags
RichTextBox
Asked by
Kamran
Top achievements
Rank 3
Iron
Veteran
Iron
Answers by
Tanya
Telerik team
Share this question
or