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

Pasted content > failed AJAX (Invalid JSON Primitive)

1 Answer 118 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Jordan
Top achievements
Rank 1
Jordan asked on 06 Apr 2010, 12:35 AM
Hi,

I have users pasting content into a radEditor in a content management system. Unfortunately the tools they are pasting from have some funny ideas about what constitutes valid HTML.

In one case, the user pasted this:

<ul> 
        <li> 
            <div style="text-align: left;"
                BLAH BLAH BLAH BLAH<span style="font-family: arial; font-size: 10px;">6 
                    <div> 
                    </div> 
                    <li> 
                        <div style="text-align: left;"
                        </div> 
                    </li> 
                </span> 
            </div> 
        </li> 
    </ul> 

You will notice that there is an <li> tag inside a <span> inside another <li> tag.

<understatement> This caused a problem. </understatement>

After this content had been saved to the database, the UpdatePanel where it was displayed could no longer successfully execute postbacks. Attempts to save the object hosting this content via a button in the panel consistently threw a JSON serialization error (Invalid JSON Primitive: .) From what I can gather, the updatePanel tried to package this invalid content up as part of its AJAX request, and the deserializer on the server blew up when presented with it. After removing the offending markup (extra <li>) in the database, the panel returned to normal operation and save attempts succeeded.

So, my question is, how can I validate user-pasted garbage to ensure that the JSON deserializer will be able to handle it? Is there an option on the editor or a recommended approach? And, when encountering invalid pasted content, is there a way to strip the offending markup?

Thanks in advance,

Jordan


1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 06 Apr 2010, 10:28 AM
Hi Jordan,

While RadEditor can compensate for a lot errors in the pasted HTML we cannon assure that every invalid entry in the HTML will be fixed. I suggest you to instruct the users to check the produced page with the built-in W3C Validator dialog (and fix the errors if it is possible), before they submit the data.

Please check this help article for more detailed information on the subject.

Greetings,
Dobromir
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Editor
Asked by
Jordan
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or