Re: Fwd:Suggested code fix for tidy
Charlie <[email protected]> Tue, 26 Jul 2005 10:00:23 -0400
| Newsgroups | gmane.comp.web.html-tidy.devel |
|---|---|
| Message-ID | <[email protected]> |
Markup like this is no fluke. It is produced, for example, by most server-side-include processors (SSIs). These typically just slurp the entire contents of the specified file and neither strip away header info (a job for Tidy --show-body-only) nor validate the character sets match. If you think about it, there are thousands of possible invalid combinations of markup. XML declarations, document types, headers, header elements, body, block structured might occur any place where they do no make sense. As it is, we have a great many of these cases coded up, but we can never possibly hope to code them all. If we did, Tidy would be huge and crash under its own weight. Note, GetToken() is called in a half-dozen different places in parser.c. Also, should we also exclude DOCTYPE declarations, XML processing instructions, etc.? A better approach, imo, that takes advantage of Tidy's design and implementation, would be to add an argument to GetToken() to be a bit mask of allowable node types. Any new nodes not expected, can be discarded as described. After the <html> element is found (or inferred), the DocType and XMLDecl node types can be removed from the current allowed node types. Once you get past the node type screen in the lexer, the existing content model checking (with all its known limitations) will kick in at the parser. My $0.02 worth anyway, Charlie At 11:44 PM 7/23/2005 -0700, Terry Teague wrote: >Forwarded to the list. > > >Date: Sat, 23 Jul 2005 16:18:31 -0700 > >From: Bastien Duclaux <[email protected]> > >Subject: Suggested code fix for tidy > >Sender: Nobody <[email protected]> > >To: [email protected] > >Cc: [email protected] > > > > >Message body follows: > > > >Hello Terry, > > > >I have found a problem with tidy, and I have a fix for it. > > > >Some sites which use XSL transformation to generate content > >have an incorrect <?xml version="1.0" encoding="...."?> tag > >inside the body of the HTML document, which makes tidy > >behave incorrectly. > > > >eg: > ><html> > > <head><title>Test Case</title></head> > > <body> > > <p>Bad! > > <?xml version="1.0" encoding="utf-8"?>blablabla > > </body> > ></html> > > > >A simply suggested fix is to add the following code block > >inside ParseHead and ParseBody function at parser.c : > > > >(main loop) > >while ((node = GetToken(doc, mode)) != NULL) > > { > > > >====> FIX > >if (node->type == XmlDecl) > > { > > ReportError(doc, &doc->root, node, > >DISCARDING_UNEXPECTED); > > FreeNode(doc, node); > > continue; > > } > >====> END FIX > > > >I hope that you will be able to include this in the next > >version. > > > >Best regards, > >Bastien > > > > >------------------------------------------------------- >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >from IBM. Find simple to follow Roadmaps, straightforward articles, >informative Webcasts and more! Get everything you need to get up to >speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >_______________________________________________ >Tidy-develop mailing list >[email protected] >https://lists.sourceforge.net/lists/listinfo/tidy-develop ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click