patch to fix a problem in the KHTMLPart::text code

Darin Adler darin at apple.com
Fri Oct 31 16:31:25 CET 2003


The endNode was getting mapped to nil in some cases. Test page was:

     <BODY>line1<BR>line2</BODY>

Test was to drag to select line 1 and then copy. You'd get the text of 
both lines.

-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/ChangeLog,v
retrieving revision 1.2172
diff -p -u -u -p -r1.2172 ChangeLog
--- ChangeLog	2003/10/31 23:40:36	1.2172
+++ ChangeLog	2003/11/01 00:30:03
@@ -1,3 +1,13 @@
+2003-10-31  Darin Adler  <darin at apple.com>
+
+        Reviewed by Ken.
+
+        - fixed 3469383 -- REGRESSION (100-111): if one line is selected on this page, too much gets copied (plain text)
+
+        * khtml/khtml_part.cpp: (KHTMLPart::text): Range check the child node indices before using them
+        to get at a child node. We don't want to set startNode or endNode to nil in any case. If the end
+        node is set to nil, we end up copying the entire remainder of the page.
+
 2003-10-31  David Hyatt  <hyatt at apple.com>
 
 	Fix for 3470007, links don't get focus on mouse down.  Fix the focus check on mouse down to actually
Index: khtml/khtml_part.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/khtml_part.cpp,v
retrieving revision 1.160
diff -p -u -u -p -r1.160 khtml/khtml_part.cpp
--- khtml/khtml_part.cpp	2003/10/27 06:54:17	1.160
+++ khtml/khtml_part.cpp	2003/11/01 00:30:05
@@ -2257,13 +2257,17 @@ QString KHTMLPart::text(const DOM::Range
   DOM::Node endNode = r.endContainer();
   int startOffset = r.startOffset();
   int endOffset = r.endOffset();
-  if (!startNode.isNull() && startNode.nodeType() == DOM::Node::ELEMENT_NODE) {
-      startOffset = -1;
-      startNode = !startNode.childNodes().isNull() ? startNode.childNodes().item(r.startOffset()) : Node();
+  if (!startNode.isNull() && startNode.nodeType() == Node::ELEMENT_NODE) {
+      if (startOffset >= 0 && startOffset < (int)startNode.childNodes().length()) {
+          startNode = startNode.childNodes().item(r.startOffset());
+          startOffset = -1;
+      }
   }
-  if (!endNode.isNull() && endNode.nodeType() == DOM::Node::ELEMENT_NODE) {
-      endOffset = -1;
-      endNode = !endNode.childNodes().isNull() ? endNode.childNodes().item(r.endOffset()-1) : Node();
+  if (!endNode.isNull() && endNode.nodeType() == Node::ELEMENT_NODE) {
+      if (endOffset > 0 && endOffset <= (int)endNode.childNodes().length()) {
+          endNode = endNode.childNodes().item(endOffset - 1);
+          endOffset = -1;
+      }
   }
 
   DOM::Node n = startNode;
-------------- next part --------------


     -- Darin


More information about the Khtml-devel mailing list