2011-01-14 Tony Chang <tony@chromium.org>
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Jan 2011 02:06:08 +0000 (02:06 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Jan 2011 02:06:08 +0000 (02:06 +0000)
        Reviewed by Alexey Proskuryakov.

        Strip NUL character when copying text on Windows
        https://bugs.webkit.org/show_bug.cgi?id=52236

        * editing/pasteboard/copy-null-characters-expected.txt: Added.
        * editing/pasteboard/copy-null-characters.html: Added.
2011-01-14  Tony Chang  <tony@chromium.org>

        Reviewed by Alexey Proskuryakov.

        Strip NUL character when copying text on Windows
        https://bugs.webkit.org/show_bug.cgi?id=52236

        Test: editing/pasteboard/copy-null-characters.html

        * editing/Editor.cpp:
        (WebCore::Editor::selectedText):
        * platform/mac/PasteboardMac.mm:
        (WebCore::Pasteboard::writeSelection): Use editor()->selectedText() which matches the other platforms.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@75861 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/copy-null-characters-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-null-characters.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp
Source/WebCore/platform/mac/PasteboardMac.mm

index d349e2f08850c652b1f94f39bc4fecc467434325..43c3d16e3fed6e7183e7719b73fe150416244a5f 100644 (file)
@@ -1,3 +1,13 @@
+2011-01-14  Tony Chang  <tony@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Strip NUL character when copying text on Windows
+        https://bugs.webkit.org/show_bug.cgi?id=52236
+
+        * editing/pasteboard/copy-null-characters-expected.txt: Added.
+        * editing/pasteboard/copy-null-characters.html: Added.
+
 2011-01-14  Nico Weber  <thakis@chromium.org>
 
         Unreviewed, test expectations.
diff --git a/LayoutTests/editing/pasteboard/copy-null-characters-expected.txt b/LayoutTests/editing/pasteboard/copy-null-characters-expected.txt
new file mode 100644 (file)
index 0000000..8f45144
--- /dev/null
@@ -0,0 +1,50 @@
+If there are NULL characters in text nodes, they should not be copied to the clipboard.  This test requires DumpRenderTree.
+| "
+"
+| <div>
+|   id="outerSource"
+|   <p>
+|     <b>
+|       "bold"
+|   "
+  "
+|   "
+  "
+|   <p>
+|     style="color: green"
+|     "green"
+|   "
+"
+| "
+"
+| <div>
+|   contenteditable="true"
+|   id="destination-rich-text"
+|   <p>
+|     <b>
+|       "bold"
+|   <div>
+|     contenteditable="true"
+|     id="source"
+|     "Copy paste me"
+|   <span>
+|     class="Apple-style-span"
+|     style="color: rgb(0, 128, 0); "
+|     "green"
+|   "Copy paste me"
+| "
+"
+| <textarea>
+|   id="destination-plain-text"
+|   this.value="Copy paste mebold
+
+Copy paste me
+green"
+| "
+"
+| <div>
+|   id="results"
+|   "PASSED"
+| "
+
+"
diff --git a/LayoutTests/editing/pasteboard/copy-null-characters.html b/LayoutTests/editing/pasteboard/copy-null-characters.html
new file mode 100644 (file)
index 0000000..c92ab8b
--- /dev/null
@@ -0,0 +1,74 @@
+<head>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+Markup.description('If there are NULL characters in text nodes, they should not be copied to the clipboard.  This test requires DumpRenderTree.');
+Markup.noAutoDump();
+
+function runTest()
+{
+    var sel = window.getSelection();
+
+    var source = document.getElementById("source");
+    var textWithNull = "Copy\0 paste me";
+    source.textContent = textWithNull;
+    sel.setPosition(source, 0);
+    document.execCommand("SelectAll");
+    document.execCommand("Copy");
+
+    var destinationRichText = document.getElementById("destination-rich-text");
+    sel.setPosition(destinationRichText, 0);
+    document.execCommand("Paste");
+
+    var destinationPlainText = document.getElementById("destination-plain-text");
+    destinationPlainText.focus();
+    document.execCommand("Paste");
+
+    var results = document.getElementById("results");
+    var expectedPlainTextValue = "Copy paste me";
+    if (expectedPlainTextValue != destinationPlainText.value) {
+        results.innerText = "Plain text field has the wrong value (expected " +
+            JSON.stringify(expectedPlainTextValue) + " but found " +
+            JSON.stringify(destinationPlainText.value) + ").";
+        return;
+    }
+
+    // Run the same test but include some richly formatted text.
+    var outerSource = document.getElementById("outerSource");
+    sel.setBaseAndExtent(outerSource, 0, destinationRichText, 0);
+    document.execCommand("Copy");
+
+    // Remove the source text so we don't end up with a null character in the
+    // expected output file.
+    source.parentNode.removeChild(source);
+
+    sel.setPosition(destinationRichText, 0);
+    document.execCommand("Paste");
+
+    destinationPlainText.focus();
+    document.execCommand("Paste");
+
+    var expectedPlainTextValue2 = "Copy paste mebold\n\nCopy paste me\ngreen";
+    if (expectedPlainTextValue2 != destinationPlainText.value) {
+        results.innerText = "Plain text field has the wrong value (expected " +
+            JSON.stringify(expectedPlainTextValue2) + " but found " +
+            JSON.stringify(destinationPlainText.value) + ").";
+        return;
+    }
+
+    results.innerText = "PASSED";
+
+    Markup.dump(document.body);
+    Markup.notifyDone();
+}
+</script>
+</head>
+
+<body onload="runTest()">
+<div id="outerSource"><p><b>bold</b></p>
+  <div id="source" contentEditable="true"></div>
+  <p style="color: green">green</p>
+</div>
+<div id="destination-rich-text" contentEditable="true"></div>
+<textarea id="destination-plain-text"></textarea>
+<div id="results">FAILED</div>
+</body>
index 0aceca3d116ce3873e83f96a701767f5cb72a0a4..af00d898b06202518e0a29b116f8b91a916d12ad 100644 (file)
@@ -1,3 +1,17 @@
+2011-01-14  Tony Chang  <tony@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Strip NUL character when copying text on Windows
+        https://bugs.webkit.org/show_bug.cgi?id=52236
+
+        Test: editing/pasteboard/copy-null-characters.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::selectedText):
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::writeSelection): Use editor()->selectedText() which matches the other platforms.
+
 2011-01-14  Yuzo Fujishima  <yuzo@google.com>
 
         Reviewed by Antti Koivisto.
index 93fdd3ce1f00692d6b27d9697ebcd515618542c7..bea74d96120d1a38fd6884a62271fccaeea6dce2 100644 (file)
@@ -3032,7 +3032,8 @@ void Editor::changeSelectionAfterCommand(const VisibleSelection& newSelection, b
 
 String Editor::selectedText() const
 {
-    return plainText(m_frame->selection()->toNormalizedRange().get());
+    // We remove '\0' characters because they are not visibly rendered to the user.
+    return plainText(m_frame->selection()->toNormalizedRange().get()).replace(0, "");
 }
 
 IntRect Editor::firstRectForRange(Range* range) const
index b1f2327cae3165ca9af0934be660ce7430d2cf19..71e40469e286ec7f3298b4c7519da0cf5de72581 100644 (file)
@@ -191,7 +191,7 @@ void Pasteboard::writeSelection(NSPasteboard* pasteboard, Range* selectedRange,
     if ([types containsObject:NSStringPboardType]) {
         // Map &nbsp; to a plain old space because this is better for source code, other browsers do it,
         // and because HTML forces you to do this any time you want two spaces in a row.
-        String text = selectedRange->text();
+        String text = frame->editor()->selectedText();
         NSMutableString *s = [[[(NSString*)text copy] autorelease] mutableCopy];
         
         NSString *NonBreakingSpaceString = [NSString stringWithCharacters:&noBreakSpace length:1];