Skip to content

Commit

Permalink
tdf#149915 Proper creation of vnd.sun.star.pkg:// URL
Browse files Browse the repository at this point in the history
Using different methods of creation (one using DecodeMechanism::NONE,
another using DecodeMechanism::WithCharset) gave differently encoded
end results, comparing unequal.

The proper way is using DecodeMechanism::NONE on the document's URL,
as implemented in commit 06756e4
  Author Mike Kaganski <[email protected]>
  Date   Sat Nov 18 22:41:40 2017 +0300
    One more proper construction of vnd.sun.star.pkg URL

Co-authored-by: Mike Kaganski <[email protected]>

Change-Id: I272f277ef8b4bd23e6cb7884e68f3c79f742683a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136901
Reviewed-by: Mike Kaganski <[email protected]>
Tested-by: Mike Kaganski <[email protected]>
  • Loading branch information
GulsahKose authored and mikekaganski committed Jul 20, 2022
1 parent f37395d commit 9790585
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions sw/source/uibase/dbui/dbmgr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ void lcl_emitEvent(SfxEventHintId nEventId, sal_Int32 nStrId, SfxObjectShell* pD
pDocShell));
}

// Construct vnd.sun.star.pkg:// URL
OUString ConstructVndSunStarPkgUrl(const OUString& rMainURL, std::u16string_view rStreamRelPath)
{
auto xContext(comphelper::getProcessComponentContext());
auto xUri = css::uri::UriReferenceFactory::create(xContext)->parse(rMainURL);
assert(xUri.is());
xUri = css::uri::VndSunStarPkgUrlReferenceFactory::create(xContext)
->createVndSunStarPkgUrlReference(xUri);
assert(xUri.is());
return xUri->getUriReference() + "/"
+ INetURLObject::encode(
rStreamRelPath, INetURLObject::PART_FPATH,
INetURLObject::EncodeMechanism::All);
}

}

std::vector<std::pair<SwDocShell*, OUString>> SwDBManager::s_aUncommittedRegistrations;
Expand Down Expand Up @@ -256,10 +271,9 @@ void SAL_CALL SwDataSourceRemovedListener::revokedDatabaseLocation(const sdb::Da
if (!pDocShell)
return;

OUString aOwnURL = pDocShell->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::WithCharset);
OUString sTmpName = "vnd.sun.star.pkg://" +
INetURLObject::encode(aOwnURL, INetURLObject::PART_AUTHORITY, INetURLObject::EncodeMechanism::All);
sTmpName += "/" + m_pDBManager->getEmbeddedName();
const OUString sTmpName = ConstructVndSunStarPkgUrl(
pDocShell->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE),
m_pDBManager->getEmbeddedName());

if (sTmpName != rEvent.OldLocation)
return;
Expand Down Expand Up @@ -2759,21 +2773,6 @@ OUString LoadAndRegisterDataSource_Impl(DBConnURIType type, const uno::Reference
}
return sFind;
}

// Construct vnd.sun.star.pkg:// URL
OUString ConstructVndSunStarPkgUrl(const OUString& rMainURL, std::u16string_view rStreamRelPath)
{
auto xContext(comphelper::getProcessComponentContext());
auto xUri = css::uri::UriReferenceFactory::create(xContext)->parse(rMainURL);
assert(xUri.is());
xUri = css::uri::VndSunStarPkgUrlReferenceFactory::create(xContext)
->createVndSunStarPkgUrlReference(xUri);
assert(xUri.is());
return xUri->getUriReference() + "/"
+ INetURLObject::encode(
rStreamRelPath, INetURLObject::PART_FPATH,
INetURLObject::EncodeMechanism::All);
}
}

OUString SwDBManager::LoadAndRegisterDataSource(weld::Window* pParent, SwDocShell* pDocShell)
Expand Down

0 comments on commit 9790585

Please sign in to comment.