summaryrefslogtreecommitdiff
path: root/ucb
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-11-26 16:29:08 +0100
committerThorsten Behrens <thorsten.behrens@allotropia.de>2021-11-27 00:18:13 +0100
commitdb8edd163cf453bbb9b85c2a17c78da49df27cdf (patch)
tree080340d1edd9bd4f608f73e839c7e438fa679040 /ucb
parent1061b3443ffbc5db0051074b428e59ba39fe24ca (diff)
ucb: webdav-curl: fix CurlUri::CloneWithRelativeRefPathAbsolute()
Change-Id: Idf1d75817009286cd79a00c0ba154cea70e2ffda Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125908 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit b03e070420606d407df2ec5e9dfa7043ecc46177) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125895 Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Diffstat (limited to 'ucb')
-rw-r--r--ucb/qa/cppunit/webdav/webdav_local_neon.cxx34
-rw-r--r--ucb/source/ucp/webdav-curl/CurlUri.cxx39
2 files changed, 58 insertions, 15 deletions
diff --git a/ucb/qa/cppunit/webdav/webdav_local_neon.cxx b/ucb/qa/cppunit/webdav/webdav_local_neon.cxx
index 08a384dee36b..bde7652b9ffa 100644
--- a/ucb/qa/cppunit/webdav/webdav_local_neon.cxx
+++ b/ucb/qa/cppunit/webdav/webdav_local_neon.cxx
@@ -43,6 +43,22 @@ namespace
CPPUNIT_ASSERT_EQUAL( OUString( "user%40anothername" ), aURI.GetUser() );
CPPUNIT_ASSERT_EQUAL( sal_uInt16( 8040 ), aURI.GetPort() );
CPPUNIT_ASSERT_EQUAL( OUString( "/aService/asegment/nextsegment/check.this?test=true&link=http://anotherserver.com/%3Fcheck=theapplication%26os=linuxintel%26lang=en-US%26version=5.2.0" ), aURI.GetRelativeReference() );
+
+ CurlUri uri2(aURI.CloneWithRelativeRefPathAbsolute(u"/foo/bar"));
+ CPPUNIT_ASSERT_EQUAL( OUString("http"), uri2.GetScheme() );
+ CPPUNIT_ASSERT_EQUAL( OUString("server.biz"), uri2.GetHost() );
+ CPPUNIT_ASSERT_EQUAL( OUString("user%40anothername"), uri2.GetUser() );
+ CPPUNIT_ASSERT_EQUAL( sal_uInt16(8040), uri2.GetPort() );
+ CPPUNIT_ASSERT_EQUAL( OUString("/foo/bar"), uri2.GetRelativeReference() );
+ CPPUNIT_ASSERT_EQUAL( OUString("http://user%40anothername@server.biz:8040/foo/bar"), uri2.GetURI() );
+
+ CurlUri uri3(aURI.CloneWithRelativeRefPathAbsolute(u"?query#fragment"));
+ CPPUNIT_ASSERT_EQUAL( OUString("http"), uri3.GetScheme() );
+ CPPUNIT_ASSERT_EQUAL( OUString("server.biz"), uri3.GetHost() );
+ CPPUNIT_ASSERT_EQUAL( OUString("user%40anothername"), uri3.GetUser() );
+ CPPUNIT_ASSERT_EQUAL( sal_uInt16(8040), uri3.GetPort() );
+ CPPUNIT_ASSERT_EQUAL( OUString("?query#fragment"), uri3.GetRelativeReference() );
+ CPPUNIT_ASSERT_EQUAL( OUString("http://user%40anothername@server.biz:8040/?query#fragment"), uri3.GetURI() );
}
void webdav_local_test::WebdavUriTest2()
@@ -54,6 +70,24 @@ namespace
CPPUNIT_ASSERT_EQUAL( OUString("bar"), aURI.GetPassword() );
CPPUNIT_ASSERT_EQUAL( sal_uInt16( 8040 ), aURI.GetPort() );
CPPUNIT_ASSERT_EQUAL( OUString( "/aService#aaa" ), aURI.GetRelativeReference() );
+
+ CurlUri uri2(aURI.CloneWithRelativeRefPathAbsolute(u"/foo/bar"));
+ CPPUNIT_ASSERT_EQUAL( OUString("https"), uri2.GetScheme() );
+ CPPUNIT_ASSERT_EQUAL( OUString("server.biz"), uri2.GetHost() );
+ CPPUNIT_ASSERT_EQUAL( OUString("foo"), uri2.GetUser() );
+ CPPUNIT_ASSERT_EQUAL( OUString("bar"), uri2.GetPassword() );
+ CPPUNIT_ASSERT_EQUAL( sal_uInt16( 8040 ), uri2.GetPort() );
+ CPPUNIT_ASSERT_EQUAL( OUString("/foo/bar"), uri2.GetRelativeReference() );
+ CPPUNIT_ASSERT_EQUAL( OUString("https://foo:bar@server.biz:8040/foo/bar"), uri2.GetURI() );
+
+ CurlUri uri3(aURI.CloneWithRelativeRefPathAbsolute(u"?query"));
+ CPPUNIT_ASSERT_EQUAL( OUString("https"), uri3.GetScheme() );
+ CPPUNIT_ASSERT_EQUAL( OUString("server.biz"), uri3.GetHost() );
+ CPPUNIT_ASSERT_EQUAL( OUString("foo"), uri3.GetUser() );
+ CPPUNIT_ASSERT_EQUAL( OUString("bar"), uri3.GetPassword() );
+ CPPUNIT_ASSERT_EQUAL( sal_uInt16(8040), uri3.GetPort() );
+ CPPUNIT_ASSERT_EQUAL( OUString("?query"), uri3.GetRelativeReference() );
+ CPPUNIT_ASSERT_EQUAL( OUString("https://foo:bar@server.biz:8040/?query"), uri3.GetURI() );
}
CPPUNIT_TEST_SUITE_REGISTRATION( webdav_local_test );
diff --git a/ucb/source/ucp/webdav-curl/CurlUri.cxx b/ucb/source/ucp/webdav-curl/CurlUri.cxx
index 533a77606f47..035c12a132ef 100644
--- a/ucb/source/ucp/webdav-curl/CurlUri.cxx
+++ b/ucb/source/ucp/webdav-curl/CurlUri.cxx
@@ -243,33 +243,42 @@ CurlUri CurlUri::CloneWithRelativeRefPathAbsolute(OUString const& rRelativeRef)
sal_Int32 indexEnd(rRelativeRef.getLength());
auto const indexQuery(rRelativeRef.indexOf('?'));
auto const indexFragment(rRelativeRef.indexOf('#'));
+ CURLUcode uc;
if (indexFragment != -1)
{
- OUString const fragment(rRelativeRef.copy(indexFragment));
+ OUString const fragment(rRelativeRef.copy(indexFragment + 1));
indexEnd = indexFragment;
OString const utf8Fragment(OUStringToOString(fragment, RTL_TEXTENCODING_UTF8));
- auto const uc = curl_url_set(pUrl.get(), CURLUPART_QUERY, utf8Fragment.getStr(), 0);
- if (uc != CURLUE_OK)
- {
- SAL_WARN("ucb.ucp.webdav.curl", "curl_url_set failed: " << uc);
- throw DAVException(DAVException::DAV_INVALID_ARG);
- }
+ uc = curl_url_set(pUrl.get(), CURLUPART_FRAGMENT, utf8Fragment.getStr(), 0);
+ }
+ else
+ {
+ uc = curl_url_set(pUrl.get(), CURLUPART_FRAGMENT, nullptr, 0);
+ }
+ if (uc != CURLUE_OK)
+ {
+ SAL_WARN("ucb.ucp.webdav.curl", "curl_url_set failed: " << uc);
+ throw DAVException(DAVException::DAV_INVALID_ARG);
}
if (indexQuery != -1 && (indexFragment == -1 || indexQuery < indexFragment))
{
- OUString const query(rRelativeRef.copy(indexQuery, indexEnd - indexQuery));
+ OUString const query(rRelativeRef.copy(indexQuery + 1, indexEnd - indexQuery - 1));
indexEnd = indexQuery;
OString const utf8Query(OUStringToOString(query, RTL_TEXTENCODING_UTF8));
- auto const uc = curl_url_set(pUrl.get(), CURLUPART_QUERY, utf8Query.getStr(), 0);
- if (uc != CURLUE_OK)
- {
- SAL_WARN("ucb.ucp.webdav.curl", "curl_url_set failed: " << uc);
- throw DAVException(DAVException::DAV_INVALID_ARG);
- }
+ uc = curl_url_set(pUrl.get(), CURLUPART_QUERY, utf8Query.getStr(), 0);
+ }
+ else
+ {
+ uc = curl_url_set(pUrl.get(), CURLUPART_QUERY, nullptr, 0);
+ }
+ if (uc != CURLUE_OK)
+ {
+ SAL_WARN("ucb.ucp.webdav.curl", "curl_url_set failed: " << uc);
+ throw DAVException(DAVException::DAV_INVALID_ARG);
}
OUString const path(rRelativeRef.copy(0, indexEnd));
OString const utf8Path(OUStringToOString(path, RTL_TEXTENCODING_UTF8));
- auto const uc = curl_url_set(pUrl.get(), CURLUPART_PATH, utf8Path.getStr(), 0);
+ uc = curl_url_set(pUrl.get(), CURLUPART_PATH, utf8Path.getStr(), 0);
if (uc != CURLUE_OK)
{
SAL_WARN("ucb.ucp.webdav.curl", "curl_url_set failed: " << uc);