Describe the bug
Executing the command returned by wxFileType::GetOpenCommand() via wxExecute() fails on Windows, if the file name or the file path contains spaces. (The bug is to some degree similar to #4607, but here the actual cause is how Edge handles the file parameter.)
Expected vs observed behaviour
For a PDF file wxFileType::GetOpenCommand() returns the command "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --single-argument %1 (unless the Windows user configured manually something else).
wxWidgets then inserts the file name for the parameter %1 and encloses it in double quotes, if it contains spaces. In principal, this should be the right thing to do. But not in this case, unfortunately.
Due to the command line switch --single-argument Edge interprets the rest of the command line as a single argument and replaces spaces by %20. The problem results from Edge replacing the leading double quote by %22 invalidating the given file name. That is, in this case, the file name should not be enclosed in double quotes, but I have no idea how wxWidgets should guess when to use quotes and when not.
The problem does not occur, if the Windows user has configured a different default PDF viewer (like for example Adobe Acrobat Reader.
To Reproduce
The problem can be reproduced by adding the following statements to any of the samples coming with wxWidgets:
#include <wx/mimetype.h> wxString pdfFile = "c:/path with spaces/file name with spaces.pdf"; // File name or file path with spaces wxFileType* fileType = wxTheMimeTypesManager->GetFileTypeFromExtension(wxT("pdf")); if (fileType != NULL) { wxString cmd = fileType->GetOpenCommand(pdfFile); if (!cmd.IsEmpty()) { wxExecute(cmd); } delete fileType; }
Platform and version information
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Unfortunately I don't really know neither. Does wxLaunchDefaultApplication() work with this association, at least?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Does
wxLaunchDefaultApplication()work with this association, at least?
Sorry for the delay. Interestingly wxLaunchDefaultApplication() does indeed work.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
So this provides a reasonable workaround for now.
As for the real solution, I'm afraid the only thing I see is to explicitly check for --single-argument and avoid quoting in this case.
It's crazy how this argument, introduced to work around bugs in other software now requires introducing our own workarounds for Chrome bugs, I really wonder what were they thinking :-(
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
So this provides a reasonable workaround for now.
Yes, fortunately.
As for the real solution, I'm afraid the only thing I see is to explicitly check for
--single-argumentand avoid quoting in this case.
Most likely there is no other way to solve it, but it is far from an elegant solution. What, if the other applications use some other obscure switch for the same purpose?
It's crazy how this argument, introduced to work around bugs in other software now requires introducing our own workarounds for Chrome bugs, I really wonder what were they thinking :-(
Did they really think? I doubt it. For command line parameters usually a string that should be treated as a single argument is simply enclosed in quotation marks. Why not stick to that rule? That would have been too easy, and much less fun for developers hunting and fixing bugs ...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I can easily believe that there are buggy programs that don't quote the arguments with spaces in them. But it boggles my mind that they didn't think to remain compatible with the correct programs that do quote it.
Still, we'll have to accommodate it, I'm afraid :-(
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()