summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-01-17 13:16:52 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-01-17 16:08:50 +0100
commitbee9f15317d8a9ac909f54791e86f29fdf6a679d (patch)
tree4586e912c7eec014a31c273c47344a7ed46bfb32
parentac8ec39c0e0cc2244d2e155d9e256b4e2ded5415 (diff)
Clean up computation of preprocessed_command passed to ShellExecuteExW
* In the URIS_ONLY case (which is intended to open documents etc.), set preprocessed_command to the filesystem pathname the first time that is computed (and which will no longer fail for file URLs with fragment since 14b36a16b225bf7c988f118d499a7287c47cd83e "Remove a fragment from a file URL early on"). * In the !URIS_ONLY case (which is intended to run other programs), we will generally be called with aCommand already being a filesystem pathname. But even if it should be a file URL, it appears to be OK to pass that as-is to ShellExecuteExW: At least on Windows 8, passing "file:///C:/Windows/System32/notepad.exe" does start it. * The code for <https://bz.apache.org/ooo/show_bug.cgi?id=4789> "Hyperlinks doesnt works" should no longer be relevant: In the URIS_ONLY case, any fragment (called a "jump mark" in that code) has already been removed from the incoming URL now. In the !URIS_ONLY case, we should generally not be called with a URL with a fragment, but even if we are, it should be OK to pass that as-is to ShellExecuteExW and let it handle that (see above). * Similarly, the code for <https://bugs.documentfoundation.org/show_bug.cgi?id=54204> "Hyperlinks between documents not works if link contains anchor at the end" is no longer relevant for the same reason. Change-Id: Ia6ec80a30f6d0603bccc87b9d6dd93ca6a84c370 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86975 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--shell/source/win32/SysShExec.cxx93
1 files changed, 1 insertions, 92 deletions
diff --git a/shell/source/win32/SysShExec.cxx b/shell/source/win32/SysShExec.cxx
index 74b4ee584f9f..42ef1b63e761 100644
--- a/shell/source/win32/SysShExec.cxx
+++ b/shell/source/win32/SysShExec.cxx
@@ -33,7 +33,6 @@
#include <cppuhelper/supportsservice.hxx>
#include <o3tl/char16_t2wchar_t.hxx>
#include <o3tl/runtimetooustring.hxx>
-#include <rtl/uri.hxx>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -163,73 +162,6 @@ namespace
#define MapError( oserror ) _mapError( oserror )
#define E_UNKNOWN_EXEC_ERROR -1
-
-
- bool is_system_path(const OUString& path_or_uri)
- {
- OUString url;
- osl::FileBase::RC rc = osl::FileBase::getFileURLFromSystemPath(path_or_uri, url);
- return (rc == osl::FileBase::E_None);
- }
-
-
- // trying to identify a jump mark
-
-
- const OUString JUMP_MARK_HTM(".htm#");
- const OUString JUMP_MARK_HTML(".html#");
- const sal_Unicode HASH_MARK = '#';
-
- bool has_jump_mark(const OUString& system_path, sal_Int32* jmp_mark_start = nullptr)
- {
- sal_Int32 jmp_mark = std::max<int>(
- system_path.lastIndexOf(JUMP_MARK_HTM),
- system_path.lastIndexOf(JUMP_MARK_HTML));
-
- if (jmp_mark_start)
- *jmp_mark_start = jmp_mark;
-
- return (jmp_mark > -1);
- }
-
-
- bool is_existing_file(const OUString& file_name)
- {
- OSL_ASSERT(is_system_path(file_name));
-
- bool exist = false;
-
- OUString file_url;
- osl::FileBase::RC rc = osl::FileBase::getFileURLFromSystemPath(file_name, file_url);
-
- if (osl::FileBase::E_None == rc)
- {
- osl::DirectoryItem dir_item;
- rc = osl::DirectoryItem::get(file_url, dir_item);
- exist = (osl::FileBase::E_None == rc);
- }
- return exist;
- }
-
-
- // Jump marks in file urls are illegal.
-
-
- void remove_jump_mark(OUString* p_command)
- {
- OSL_PRECOND(p_command, "invalid parameter");
-
- sal_Int32 pos;
- if (has_jump_mark(*p_command, &pos))
- {
- const sal_Unicode* p_jmp_mark = p_command->getStr() + pos;
- while (*p_jmp_mark && (*p_jmp_mark != HASH_MARK))
- p_jmp_mark++;
-
- *p_command = OUString(p_command->getStr(), p_jmp_mark - p_command->getStr());
- }
- }
-
}
CSysShExec::CSysShExec( const Reference< css::uno::XComponentContext >& xContext ) :
@@ -318,7 +250,6 @@ void SAL_CALL CSysShExec::execute( const OUString& aCommand, const OUString& aPa
if (uri->getScheme().equalsIgnoreAsciiCase("file")) {
// ShellExecuteExW appears to ignore the fragment of a file URL anyway, so remove it:
uri->clearFragment();
- preprocessed_command = uri->getUriReference();
OUString pathname;
auto const e1
= osl::FileBase::getSystemPathFromFileURL(uri->getUriReference(), pathname);
@@ -328,6 +259,7 @@ void SAL_CALL CSysShExec::execute( const OUString& aCommand, const OUString& aPa
+ "> failed with " + OUString::number(e1)),
{}, 0);
}
+ preprocessed_command = pathname;
for (int i = 0;; ++i) {
SHFILEINFOW info;
if (SHGetFileInfoW(
@@ -417,29 +349,6 @@ void SAL_CALL CSysShExec::execute( const OUString& aCommand, const OUString& aPa
}
}
- /* #i4789#; jump mark detection on system paths
- if the given command is a system path (not http or
- other uri schemes) and seems to have a jump mark
- and names no existing file (remember the jump mark
- sign '#' is a valid file name character we remove
- the jump mark, else ShellExecuteEx fails */
- if (is_system_path(preprocessed_command))
- {
- if (has_jump_mark(preprocessed_command) && !is_existing_file(preprocessed_command))
- remove_jump_mark(&preprocessed_command);
- }
- /* Convert file uris to system paths */
- else
- {
- OUString aSystemPath;
- if (::osl::FileBase::E_None == ::osl::FileBase::getSystemPathFromFileURL(preprocessed_command, aSystemPath))
- preprocessed_command = aSystemPath;
- else if (preprocessed_command.startsWithIgnoreAsciiCase("file:"))
- //I use ToIUri conversion instead of the translateToExternal method of the css.uri.ExternalUriReferenceTranslator
- //UNO service, because the translateToExternal method only supports characters covered by the current Windows code page.
- preprocessed_command = rtl::Uri::decode(preprocessed_command, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8);
- }
-
SHELLEXECUTEINFOW sei;
ZeroMemory(&sei, sizeof( sei));