Bugs item #1636028, was opened at 2007-01-15 17:27
Message generated for change (Settings changed) made by hoehrmann
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=390963&aid=1636028&group_id=27659
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: TidyLib APIs
Group: Current - all platforms
Status: Open
Resolution: None
Priority: 6
Private: No
Submitted By: ayermakov (ayermakov)
>
Assigned to: Nobody/Anonymous (nobody)
Summary: Tidy API function tidyNodeGetText escapes output
Initial Comment:
We use tidy mainly through its API, we walk parse tree and extract information
about each node in the tree, and transform it in our own tree structure. The
issue happens when we use tidyNodeGetText() on the TidyNode_Text,
TidyNode_Comment and TidyNode_CDATA type of node.
Consider the input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT type="text/javascript">document.write("<STYLE>");</SCRIPT>
</HEAD>
<BODY>
Hello!
</BODY>
</HTML>
I'm walking the tidy parse tree and print out a text of each node (for
simplicity reasons). Here is a small function to walk the tree:
static void processNode(TidyDoc tdoc, TidyNode tnod)
{
TidyNode child;
for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) )
{
ctmbstr name = tidyNodeGetName( child );
TidyNodeType type = tidyNodeGetType(child);
switch ( type )
{
case TidyNode_Comment:
{
TidyBuffer text = {0};
tidyBufInit(&text);
if (tidyNodeGetText(tdoc, child, &text))
{
printf("TidyNode_Comment: %s\n",
text.bp);
tidyBufFree(&text);
}
}
break;
case TidyNode_Text:
{
TidyBuffer text = {0};
tidyBufInit(&text);
if (tidyNodeGetText(tdoc, child, &text))
{
printf("TidyNode_Text: %s\n", text.bp);
tidyBufFree(&text);
}
}
break;
case TidyNode_CDATA:
{
TidyBuffer text = {0};
tidyBufInit(&text);
if (tidyNodeGetText(tdoc, child, &text))
{
printf("TidyNode_CDATA: %s\n", text.bp);
tidyBufFree(&text);
}
}
break;
case TidyNode_Start:
{
processNode( tdoc, child);
}
break;
default:
break;
}
}
}
I call the function as follows:
processNode(tdoc, tidyGetRoot(tdoc));
The output of the function is:
TidyNode_Text: New Document
TidyNode_Text: document.write("<STYLE>");
TidyNode_Text: Hello!
Note that angle brackets converted to sgml entities. It's not clear why, seems
a bug to me.
Even if there is some reason behind this, we would like to get an undistorted
original text without escaping. Is there any option to do that?
----------------------------------------------------------------------
Comment By: BjÃrn HÃhrmann (hoehrmann)
Date: 2007-01-17 00:02
Message:
Logged In: YES
user_id=188003
Originator: NO
tidyNodeGetText is supposed to partially serialize a node, it is not meant
to get an element's text content, I think it would be incorrect for it to
not escape special characters in text. We lack a function to get the
content of text nodes, see the Jan 2003 thread "How to access lexbuf?" on
tidy-develop. I think the addition of such a function would address the
requestor's problem.
If tidyNodeGetText is to improved indepentently of the addition of such a
function, it should continue to escape normal text nodes, whether CDATA
element content like for <script> and <style> is escaped should depend on
whether XML/XHTML output is requested, and the content of comments and PIs
should probably never be escaped as if it was text.
----------------------------------------------------------------------
Comment By: Arnaud Desitter (arnaud02)
Date: 2007-01-16 23:35
Message:
Logged In: YES
user_id=566665
Originator: NO
Bjoern,
Could you comment on this patch ?
Thanks,
----------------------------------------------------------------------
Comment By: ayermakov (ayermakov)
Date: 2007-01-16 14:58
Message:
Logged In: YES
user_id=1688233
Originator: YES
Well, seems the bug entry 1166491 describes the same issue. However I do
have a slightly different opinion how it should be resolved. I believe that
tidyNodeGetText should output text of any node 'as-is', without any
processing (escaping). It's true not only for script and style type of
node, but also for a regular html text.
Or at least it should be under control of some option.
File Added: 1636028.diff
----------------------------------------------------------------------
Comment By: Arnaud Desitter (arnaud02)
Date: 2007-01-16 09:44
Message:
Logged In: YES
user_id=566665
Originator: NO
See
http://tidy.sf.net/issue/1166491 which contains a patch that may be
correct.
It would be nice if you could provide a patch with a rationale so this
issue could be nailed down.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=390963&aid=1636028&group_id=27659
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Tidy-tracker mailing list
Tidy-tracker@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/tidy-tracker