Title: [116408] trunk
Revision
116408
Author
[email protected]
Date
2012-05-08 02:43:19 -0700 (Tue, 08 May 2012)

Log Message

Extra line-breaks added when copying from source.
https://bugs.webkit.org/show_bug.cgi?id=85282

Reviewed by Ryosuke Niwa.

Source/WebCore:

The code used to replace any \n by \r\n, even the one that had a preceding \r, resulting in \r\r\n.
This change introduces a check for the preceding \r when replacing \n's.

Test: platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win.html

* platform/chromium/ClipboardUtilitiesChromium.cpp:
(WebCore::replaceNewlinesWithWindowsStyleNewlines):
* platform/win/ClipboardUtilitiesWin.cpp:
(WebCore::replaceNewlinesWithWindowsStyleNewlines):

LayoutTests:

* platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win-expected.txt: Added.
* platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (116407 => 116408)


--- trunk/LayoutTests/ChangeLog	2012-05-08 09:28:30 UTC (rev 116407)
+++ trunk/LayoutTests/ChangeLog	2012-05-08 09:43:19 UTC (rev 116408)
@@ -1,3 +1,13 @@
+2012-05-03  Alexander Pavlov  <[email protected]>
+
+        Extra line-breaks added when copying from source.
+        https://bugs.webkit.org/show_bug.cgi?id=85282
+
+        Reviewed by Ryosuke Niwa.
+
+        * platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win-expected.txt: Added.
+        * platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win.html: Added.
+
 2012-05-08  János Badics  <[email protected]>
 
         [Qt] Gardening after 116361. Updated expected result.

Added: trunk/LayoutTests/platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win-expected.txt (0 => 116408)


--- trunk/LayoutTests/platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win-expected.txt	2012-05-08 09:43:19 UTC (rev 116408)
@@ -0,0 +1,6 @@
+This test requires DRT. It verifies that on Windows only \n's not preceded by \r are translated into \r\n by Pasteboard.
+
+Source:
+\nLine1\rLine2\nLine3\r\nLine4\r\r\nLine5\r\n\r\n\n
+Result:
+\r\nLine1\rLine2\r\nLine3\r\nLine4\r\r\nLine5\r\n\r\n\r\n
Property changes on: trunk/LayoutTests/platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win.html (0 => 116408)


--- trunk/LayoutTests/platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win.html	                        (rev 0)
+++ trunk/LayoutTests/platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win.html	2012-05-08 09:43:19 UTC (rev 116408)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+
+function handlePaste(event)
+{
+    var data = ""
+    document.getElementById("result").textContent += data.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
+    event.preventDefault();
+}
+
+function runTest()
+{
+    if (!window.layoutTestController)
+        return;
+    window.layoutTestController.dumpAsText();
+
+    document.body.addEventListener('paste', handlePaste);
+    var sourceElement = document.getElementById('source');
+    var originalSource = sourceElement.textContent;
+    sourceElement.textContent = originalSource.replace(/[\\]r/g, "\r").replace(/[\\]n/g, "\n");
+
+    var range = document.createRange();
+    range.selectNode(sourceElement);
+    getSelection().addRange(range);
+    document.execCommand('copy');
+    getSelection().removeAllRanges();
+    sourceElement.textContent = originalSource;
+
+    document.execCommand('paste');
+}
+</script>
+<body _onload_="runTest()" contenteditable="true">
+<p id="description">This test requires DRT. It verifies that on Windows only \n's not preceded by \r are translated into \r\n by Pasteboard.</p>
+<div>Source:</div>
+<pre id="source">\nLine1\rLine2\nLine3\r\nLine4\r\r\nLine5\r\n\r\n\n</pre>
+<div>Result:</div>
+<div id="result" />
+</body>
+</html>
+
Property changes on: trunk/LayoutTests/platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (116407 => 116408)


--- trunk/Source/WebCore/ChangeLog	2012-05-08 09:28:30 UTC (rev 116407)
+++ trunk/Source/WebCore/ChangeLog	2012-05-08 09:43:19 UTC (rev 116408)
@@ -1,3 +1,20 @@
+2012-05-03  Alexander Pavlov  <[email protected]>
+
+        Extra line-breaks added when copying from source.
+        https://bugs.webkit.org/show_bug.cgi?id=85282
+
+        Reviewed by Ryosuke Niwa.
+
+        The code used to replace any \n by \r\n, even the one that had a preceding \r, resulting in \r\r\n.
+        This change introduces a check for the preceding \r when replacing \n's.
+
+        Test: platform/win/editing/pasteboard/pasting-crlf-isnt-translated-to-crcrlf-win.html
+
+        * platform/chromium/ClipboardUtilitiesChromium.cpp:
+        (WebCore::replaceNewlinesWithWindowsStyleNewlines):
+        * platform/win/ClipboardUtilitiesWin.cpp:
+        (WebCore::replaceNewlinesWithWindowsStyleNewlines):
+
 2012-05-08  Adam Barth  <[email protected]>
 
         OS(ANDROID) JNI AttachCurrentThread take JNIEnv** as a parameter, not void**

Modified: trunk/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp (116407 => 116408)


--- trunk/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp	2012-05-08 09:28:30 UTC (rev 116407)
+++ trunk/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp	2012-05-08 09:43:19 UTC (rev 116408)
@@ -47,9 +47,20 @@
 #if OS(WINDOWS)
 void replaceNewlinesWithWindowsStyleNewlines(String& str)
 {
-    static const UChar Newline = '\n';
-    static const char* const WindowsNewline("\r\n");
-    str.replace(Newline, WindowsNewline);
+    DEFINE_STATIC_LOCAL(String, windowsNewline, ("\r\n"));
+    const static unsigned windowsNewlineLength = windowsNewline.length();
+
+    unsigned index = 0;
+    unsigned strLength = str.length();
+    while (index < strLength) {
+        if (str[index] != '\n' || (index > 0 && str[index - 1] == '\r')) {
+            ++index;
+            continue;
+        }
+        str.replace(index, 1, windowsNewline);
+        strLength = str.length();
+        index += windowsNewlineLength;
+    }
 }
 #endif
 

Modified: trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp (116407 => 116408)


--- trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp	2012-05-08 09:28:30 UTC (rev 116407)
+++ trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp	2012-05-08 09:43:19 UTC (rev 116408)
@@ -298,9 +298,20 @@
 
 void replaceNewlinesWithWindowsStyleNewlines(String& str)
 {
-    static const UChar Newline = '\n';
-    static const char* const WindowsNewline("\r\n");
-    str.replace(Newline, WindowsNewline);
+    DEFINE_STATIC_LOCAL(String, windowsNewline, ("\r\n"));
+    const static unsigned windowsNewlineLength = windowsNewline.length();
+
+    unsigned index = 0;
+    unsigned strLength = str.length();
+    while (index < strLength) {
+        if (str[index] != '\n' || (index > 0 && str[index - 1] == '\r')) {
+            ++index;
+            continue;
+        }
+        str.replace(index, 1, windowsNewline);
+        strLength = str.length();
+        index += windowsNewlineLength;
+    }
 }
 
 void replaceNBSPWithSpace(String& str)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to