loleaflet/src/layer/tile/TileLayer.js | 2 +- loolwsd/LOOLSession.cpp | 11 ++++++----- loolwsd/LOOLWSD.cpp | 12 ++++++++---- loolwsd/protocol.txt | 3 ++- loolwsd/test/httpwstest.cpp | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-)
New commits: commit fde59b7c4c3ab7193c12334930709b00a670d62f Author: Miklos Vajna <[email protected]> Date: Fri Jan 15 14:42:02 2016 +0100 paste: handle data containing newlines By changing the protocol, so that instead of "paste ... data=<data>", the client is now expected to send "paste ...\n<data>". (cherry picked from commit 1977f07d5c406b5bcecc9a0f8e9a2da7af4e2c09) Conflicts: loolwsd/ChildProcessSession.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index c868b8e..e08754f 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -934,7 +934,7 @@ L.TileLayer = L.GridLayer.extend({ _onPaste: function (e) { e = e.originalEvent; e.preventDefault(); - this._map._socket.sendMessage('paste mimetype=text/plain;charset=utf-8 data=' + e.clipboardData.getData('text/plain')); + this._map._socket.sendMessage('paste mimetype=text/plain;charset=utf-8\n' + e.clipboardData.getData('text/plain')); }, _onDragOver: function (e) { diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index e920adb..5e11e1d 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -1461,20 +1461,21 @@ bool ChildProcessSession::getTextSelection(const char* /*buffer*/, int /*length* return true; } -bool ChildProcessSession::paste(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens) +bool ChildProcessSession::paste(const char* buffer, int length, StringTokenizer& tokens) { std::string mimeType; - std::string data; - if (tokens.count() < 3 || !getTokenString(tokens[1], "mimetype", mimeType) || !getTokenString(tokens[2], "data", data)) + if (tokens.count() < 2 || !getTokenString(tokens[1], "mimetype", mimeType)) { sendTextFrame("error: cmd=paste kind=syntax"); return false; } - data = Poco::cat(std::string(" "), tokens.begin() + 2, tokens.end()).substr(strlen("data=")); + const std::string firstLine = getFirstLine(buffer, length); + const char* data = buffer + firstLine.size() + 1; + size_t size = length - firstLine.size() - 1; - _loKitDocument->pClass->paste(_loKitDocument, mimeType.c_str(), data.c_str(), std::strlen(data.c_str())); + _loKitDocument->pClass->paste(_loKitDocument, mimeType.c_str(), data, size); return true; } diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index c1434e1..375874c 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1071,10 +1071,14 @@ void LOOLWSD::componentMain() std::string firstLine = getFirstLine(buffer, n); StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); - // The only kind of messages a child process receives are the single-line ones (?) - assert(firstLine.size() == static_cast<std::string::size_type>(n)); - - queue.put(firstLine); + if (firstLine.find("paste") != 0) + { + // Everything else is expected to be a single line. + assert(firstLine.size() == static_cast<std::string::size_type>(n)); + queue.put(firstLine); + } + else + queue.put(std::string(buffer, n)); } } while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE); diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt index e9cce86..1d8890d 100644 --- a/loolwsd/protocol.txt +++ b/loolwsd/protocol.txt @@ -31,7 +31,8 @@ gettextselection mimetype=<mimeType> Request selection's content -paste mimetype=<mimeType> data=<data> +paste mimetype=<mimeType> +<binaryPasteData> Paste content at the current cursor position. diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index 1caf632..3846151 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -56,7 +56,7 @@ void HTTPWSTest::testPaste() sendTextFrame(_socket, "uno .uno:Delete"); // Paste some text into it. - sendTextFrame(_socket, "paste mimetype=text/plain;charset=utf-8 data=aaa bbb ccc"); + sendTextFrame(_socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc"); // Check if the document contains the pasted text. sendTextFrame(_socket, "uno .uno:SelectAll"); _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
