From 54d07afac60d68fae9910724c5f273658e9a82cc Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 7 May 2023 11:49:48 +0300 Subject: [PATCH] tdf#155176: only use item's URL in case filesystem path failed I was daydreaming, when thought that we can rely on the system-provided file URL. Windows creates such URLs using current 8-bit codepage, and URL-encodes the octets from that string, which fails when the URL is treated as UTF-8 after URL-decode. Change-Id: I2703586d371c1254e693a5760c5b6b74101e299d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151456 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- fpicker/source/win32/VistaFilePickerImpl.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fpicker/source/win32/VistaFilePickerImpl.cxx b/fpicker/source/win32/VistaFilePickerImpl.cxx index fa58efc6c5d9..67e977156bd2 100644 --- a/fpicker/source/win32/VistaFilePickerImpl.cxx +++ b/fpicker/source/win32/VistaFilePickerImpl.cxx @@ -170,12 +170,15 @@ using TFolderPickerDialogImpl = TDialogImpl pStr; - if (SUCCEEDED(pItem->GetDisplayName(SIGDN_URL, &pStr))) - return OUString(o3tl::toU(pStr)); - HRESULT hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pStr); if (FAILED(hr)) { + // tdf#155176: One could think that querying SIGDN_URL would go first. But Windows uses + // current 8-bit codepage for the filenames, and URL-encodes those octets. So check it + // only after SIGDN_FILESYSPATH query failed (can it ever happen?) + if (SUCCEEDED(pItem->GetDisplayName(SIGDN_URL, &pStr))) + return OUString(o3tl::toU(pStr)); + hr = pItem->GetDisplayName(SIGDN_PARENTRELATIVEPARSING, &pStr); if (SUCCEEDED(hr)) {