diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 50f6239455..260579a7a7 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -1273,7 +1273,7 @@ bool ChildSession::getClipboard(const StringVector& tokens) // FIXME: extra 'content' is necessary for Message parsing. Util::vectorAppend(output, "clipboardcontent: content\n"); - bool json = specifics.size() > 1; + bool json = !specifics.empty(); Poco::JSON::Object selectionObject; LOG_TRC("Building clipboardcontent: " << nOutCount << " items"); for (size_t i = 0; i < nOutCount; ++i) diff --git a/test/UnitCopyPasteWriter.cpp b/test/UnitCopyPasteWriter.cpp index 32e17fc946..727ce23f8e 100644 --- a/test/UnitCopyPasteWriter.cpp +++ b/test/UnitCopyPasteWriter.cpp @@ -77,20 +77,37 @@ public: // Then make sure asking for multiple, specific formats results in a JSON answer, it's what // JS expects: - std::string clipURI = getSessionClipboardURI(0); - clipURI += "&MimeType=text/html,text/plain;charset=utf-8"; - std::shared_ptr httpSession = http::Session::create(clipURI); - std::shared_ptr httpResponse = - httpSession->syncRequest(http::Request(Poco::URI(clipURI).getPathAndQuery())); - LOK_ASSERT_EQUAL(http::StatusCode::OK, httpResponse->statusLine().statusCode()); - std::string body = httpResponse->getBody(); - Poco::JSON::Object::Ptr object; - // This failed, we didn't return JSON. - LOK_ASSERT(JsonUtil::parseJSON(body, object)); - LOK_ASSERT(object->has("text/html")); - std::string expectedPlainText(" • first\n • second\n • third"); - std::string actualPlainText = object->get("text/plain;charset=utf-8").toString(); - LOK_ASSERT_EQUAL(actualPlainText, expectedPlainText); + { + std::string clipURI = getSessionClipboardURI(0); + clipURI += "&MimeType=text/html,text/plain;charset=utf-8"; + std::shared_ptr httpSession = http::Session::create(clipURI); + std::shared_ptr httpResponse = + httpSession->syncRequest(http::Request(Poco::URI(clipURI).getPathAndQuery())); + LOK_ASSERT_EQUAL(http::StatusCode::OK, httpResponse->statusLine().statusCode()); + std::string body = httpResponse->getBody(); + Poco::JSON::Object::Ptr object; + // This failed, we didn't return JSON. + LOK_ASSERT(JsonUtil::parseJSON(body, object)); + LOK_ASSERT(object->has("text/html")); + std::string expectedPlainText(" • first\n • second\n • third"); + std::string actualPlainText = object->get("text/plain;charset=utf-8").toString(); + LOK_ASSERT_EQUAL(actualPlainText, expectedPlainText); + } + + // Now also test HTML only: + { + std::string clipURI = getSessionClipboardURI(0); + clipURI += "&MimeType=text/html"; + std::shared_ptr httpSession = http::Session::create(clipURI); + std::shared_ptr httpResponse = + httpSession->syncRequest(http::Request(Poco::URI(clipURI).getPathAndQuery())); + LOK_ASSERT_EQUAL(http::StatusCode::OK, httpResponse->statusLine().statusCode()); + std::string body = httpResponse->getBody(); + Poco::JSON::Object::Ptr object; + LOK_ASSERT(JsonUtil::parseJSON(body, object)); + LOK_ASSERT(object->has("text/html")); + } + TRANSITION_STATE(_phase, Phase::WaitDocClose); socket->asyncShutdown(); LOK_ASSERT(socket->waitForDisconnection(std::chrono::seconds(5)));