diff --git a/editor/libeditor/text/nsPlaintextDataTransfer.cpp b/editor/libeditor/text/nsPlaintextDataTransfer.cpp index 0b6c79564d6d..209c08f575a0 100644 --- a/editor/libeditor/text/nsPlaintextDataTransfer.cpp +++ b/editor/libeditor/text/nsPlaintextDataTransfer.cpp @@ -68,6 +68,7 @@ #include "nsISelectionPrivate.h" #include "nsFrameSelection.h" #include "nsEventDispatcher.h" +#include "nsContentUtils.h" NS_IMETHODIMP nsPlaintextEditor::PrepareTransferable(nsITransferable **transferable) { @@ -136,6 +137,10 @@ NS_IMETHODIMP nsPlaintextEditor::InsertTextFromTransferable(nsITransferable *aTr nsAutoString stuffToPaste; textDataObj->GetData(stuffToPaste); NS_ASSERTION(stuffToPaste.Length() <= (len/2), "Invalid length!"); + + // Sanitize possible carriage returns in the string to be inserted + nsContentUtils::PlatformToDOMLineBreaks(stuffToPaste); + nsAutoEditBatch beginBatching(this); rv = InsertTextAt(stuffToPaste, aDestinationNode, aDestOffset, aDoDeleteSelection); } diff --git a/editor/libeditor/text/tests/Makefile.in b/editor/libeditor/text/tests/Makefile.in index 4572909aac55..ac9980328c26 100644 --- a/editor/libeditor/text/tests/Makefile.in +++ b/editor/libeditor/text/tests/Makefile.in @@ -63,6 +63,7 @@ _TEST_FILES = \ test_bug638596.html \ test_bug641466.html \ test_bug645914.html \ + test_bug681229.html \ $(NULL) # disables the key handling test on gtk2 because gtk2 overrides some key events diff --git a/editor/libeditor/text/tests/test_bug681229.html b/editor/libeditor/text/tests/test_bug681229.html new file mode 100644 index 000000000000..05710e4eb164 --- /dev/null +++ b/editor/libeditor/text/tests/test_bug681229.html @@ -0,0 +1,51 @@ + + + +
++ ++ + diff --git a/testing/mochitest/specialpowers/content/specialpowers.js b/testing/mochitest/specialpowers/content/specialpowers.js index 89c260fe26cc..7b4c141d6b62 100644 --- a/testing/mochitest/specialpowers/content/specialpowers.js +++ b/testing/mochitest/specialpowers/content/specialpowers.js @@ -418,6 +418,12 @@ SpecialPowers.prototype = { getDocumentURIObject: function(aDocument) { return aDocument.documentURIObject; }, + + copyString: function(str) { + Cc["@mozilla.org/widget/clipboardhelper;1"]. + getService(Ci.nsIClipboardHelper). + copyString(str); + }, }; // Expose everything but internal APIs (starting with underscores) to