[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/4.4/kdelibs/khtml/xml
From:       Harri Porten <porten () kde ! org>
Date:       2010-02-14 20:46:34
Message-ID: 1266180394.696205.5498.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1090190 by porten:

Merged revision 1090189:
More exceptions for escaping in HTML conversion.

Compared to what the HTML 5 spec and other browsers do. No clear picture.
Affects both .innerHTML property and clipboard copies.

 M  +25 -10    dom_textimpl.cpp  


--- branches/KDE/4.4/kdelibs/khtml/xml/dom_textimpl.cpp #1090189:1090190
@@ -564,20 +564,36 @@
         return string();
 }
 
+static bool textNeedsEscaping( const NodeImpl *n )
+{
+    // Exceptions based on "Serializing HTML fragments" section of
+    // HTML 5 specification (with some adaptions to reality)
+    const NodeImpl *p = n->parentNode();
+    if ( !p )
+        return true;
+    switch ( p->id() ) {
+    case ID_IFRAME:
+        // follow deviating examples of FF 3.5.6 and Opera 9.6
+        // case ID_NOEMBED:
+        // case ID_NOFRAMES:
+    case ID_NOSCRIPT:
+    case ID_PLAINTEXT:
+    case ID_SCRIPT:
+    case ID_STYLE:
+    case ID_XMP:
+        return false;
+    default:
+        return true;
+    }
+}
+
 DOMString TextImpl::toString() const
 {
-    // FIXME: substitute entity references as needed!
-    bool escape = true;
-    for (NodeImpl* node = parentNode(); node; node = node->parentNode())
-        if (node->id() == ID_SCRIPT)
-            escape = false;
-    return escape ? escapeHTML( nodeValue() ) : nodeValue();
+    return textNeedsEscaping( this ) ? escapeHTML( nodeValue() ) : nodeValue();
 }
 
 DOMString TextImpl::toString(long long startOffset, long long endOffset) const
 {
-    // FIXME: substitute entity references as needed!
-
     DOMString str = nodeValue();
     if(endOffset >=0 || startOffset >0)
 	str = str.copy(); //we are going to modify this, so make a copy.  I hope I'm doing \
this right. @@ -585,7 +601,7 @@
         str.truncate(endOffset); 
     if(startOffset > 0)    //note the order of these 2 'if' statements so that it \
works right when n==m_startContainer==m_endContainer  str.remove(0, startOffset);
-    return escapeHTML( str );
+    return textNeedsEscaping( this ) ? escapeHTML( str ) : str;
 }
 
 // ---------------------------------------------------------------------------
@@ -618,7 +634,6 @@
 
 DOMString CDATASectionImpl::toString() const
 {
-    // FIXME: substitute entity references as needed!
     return DOMString("<![CDATA[") + nodeValue() + "]]>";
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic