[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-4' - test/UnitWOPISaveAs.cpp test/WopiTestServer.hpp wsd/ClientSession.cpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Mar 20 10:29:13 UTC 2019


 test/UnitWOPISaveAs.cpp |    7 ++++---
 test/WopiTestServer.hpp |    2 +-
 wsd/ClientSession.cpp   |   14 +++++++++-----
 3 files changed, 14 insertions(+), 9 deletions(-)

New commits:
commit 1926bee07e1c8c7a452fc0bd59235d6a6e540271
Author:     Eduard Ardeleanu <eduard-andrei.ardeleanu at 1and1.ro>
AuthorDate: Tue Mar 19 16:00:38 2019 +0200
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Tue Mar 19 18:34:36 2019 +0100

    fix: saveAs breaks when '%' character is used within the filename
    
    Change-Id: I2df059abd67be88acae8bd44ae2c74be7778a595
    Reviewed-on: https://gerrit.libreoffice.org/69424
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/test/UnitWOPISaveAs.cpp b/test/UnitWOPISaveAs.cpp
index 7d9be30f9..449100681 100644
--- a/test/UnitWOPISaveAs.cpp
+++ b/test/UnitWOPISaveAs.cpp
@@ -34,7 +34,7 @@ public:
     void assertPutRelativeFileRequest(const Poco::Net::HTTPRequest& request) override
     {
         // spec says UTF-7...
-        CPPUNIT_ASSERT_EQUAL(std::string("/jan/hole+AWE-ovsk+AP0-/hello world.pdf"), request.get("X-WOPI-SuggestedTarget"));
+        CPPUNIT_ASSERT_EQUAL(std::string("/jan/hole+AWE-ovsk+AP0-/hello world+ACU-1.pdf"), request.get("X-WOPI-SuggestedTarget"));
 
         // make sure it is a pdf - or at least that it is larger than what it
         // used to be
@@ -44,7 +44,8 @@ public:
     bool filterSendMessage(const char* data, const size_t len, const WSOpCode /* code */, const bool /* flush */, int& /*unitReturn*/) override
     {
         const std::string message(data, len);
-        const std::string expected("saveas: url=" + helpers::getTestServerURI() + "/something%20wopi/files/1?access_token=anything filename=hello%20world.pdf");
+
+        const std::string expected("saveas: url=" + helpers::getTestServerURI() + "/something%20wopi/files/1?access_token=anything filename=hello%20world%251.pdf");
         if (message.find(expected) == 0)
         {
             // successfully exit the test if we also got the outgoing message
@@ -66,7 +67,7 @@ public:
                 initWebsocket("/wopi/files/0?access_token=anything");
 
                 helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "load url=" + _wopiSrc, testName);
-                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "saveas url=wopi:///jan/hole%C5%A1ovsk%C3%BD/hello%20world.pdf", testName);
+                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "saveas url=wopi:///jan/hole%C5%A1ovsk%C3%BD/hello%20world%251.pdf", testName);
                 SocketPoll::wakeupWorld();
 
                 _phase = Phase::Polling;
diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp
index cc951f9c6..3e95c3b8b 100644
--- a/test/WopiTestServer.hpp
+++ b/test/WopiTestServer.hpp
@@ -166,7 +166,7 @@ protected:
             assertPutRelativeFileRequest(request);
 
             std::string wopiURL = helpers::getTestServerURI() + "/something wopi/files/1?access_token=anything";
-            std::string content = "{ \"Name\":\"hello world.pdf\", \"Url\":\"" + wopiURL + "\" }";
+            std::string content = "{ \"Name\":\"hello world%1.pdf\", \"Url\":\"" + wopiURL + "\" }";
 
             std::ostringstream oss;
             oss << "HTTP/1.1 200 OK\r\n"
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index f3afc4efc..665056f30 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -800,12 +800,12 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
             return false;
         }
 
-        std::string url, wopiFilename;
-        Poco::URI::decode(encodedURL, url);
+        // Save-as completed, inform the ClientSession.
+        std::string wopiFilename;
         Poco::URI::decode(encodedWopiFilename, wopiFilename);
 
-        // Save-as completed, inform the ClientSession.
-        Poco::URI resultURL(url);
+        // URI constructor implicitly decodes when it gets std::string as param
+        Poco::URI resultURL(encodedURL);
         if (resultURL.getScheme() == "file")
         {
             std::string relative(resultURL.getPath());
@@ -816,7 +816,11 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
             const Path path(docBroker->getJailRoot(), relative);
             if (Poco::File(path).exists())
             {
-                resultURL.setPath(path.toString());
+                // Encode path for special characters (i.e '%') since Poco::URI::setPath implicitly decodes the input param
+                std::string encodedPath;
+                Poco::URI::encode(path.toString(), "", encodedPath);
+
+                resultURL.setPath(encodedPath);
             }
             else
             {


More information about the Libreoffice-commits mailing list