Originally posted by oiaohm
View Post
- Does the application send its URLs as text/plain but not text/uri-list? PCManFM for GTK+ 2.x's "Copy Path(s)" option does and users will still expect that to Just Work⢠in my application.
- Does the application only offer "path to clipboard" in a pre-shell-escaped form meant for pasting into terminals? GQview/Geeqie does.
- Does the application use file://localhost/ instead of file:///? Comix does and QUrl.toLocalFile() maps that to //localhost/ as if it were a UNC path (which is actually consistent with a "this is implementation-defined" part of POSIX), but other code doesn't know how to deal with that.
- Does Chrome/Chromium sometimes send text/uri-list in a little-endian UTF-16 form that QMimeData resolves to QUrl(""), triggering my fallback to the UTF-8 text/plain version? Yes.
- Does the application use \n or \r\n to separate the list of URLs or file paths when it's sending them via a mechanism QMimeData doesn't normalize? Does it include or omit a terminal \n or \r\n? It depends on the application. (I believe the spec calls for \r\n and one at the end of the final line, but that's alien enough to Linux and '\n'.join(url_list) that you see a lot of apps messing it up. In fact, I think this is the quirk that breaks drag-and-drop from Audacious Media Player to Firefox.)
- Do you have to parse an HTML fragment (ie. multiple root elements) out of the text/html content type offer if you want the image data and the original URL (eg. to support both First/Prev/Next/Last buttons for local files and remote "must be logged in" images)? Firefox and Chromium's "Copy Image" do that.
- Is the text/html content in little-endian UTF-16 or UTF-8? It depends on whether you chose to "Copy Image" or Drag and Drop in Firefox... luckily, the UTF-16 text/html is accompanied by the URL offered as text/plain.
- What precedence order do I need to use in my fallback chain when a browser offers up multiple representations of a file? That took gathering output from various browsers and writing a test suite.
- Chrome sometimes randomly neglects to include the raw image data as an option when dragging and dropping a "you must be logged in to view this" image from Pixiv? I have to detect and display an explanatory dialog in the part of my code that performs network requests.
- Does text/plain contain a URL or a path? Does it percent-escape when constructing a file:// URL or construct something primarily intended for human viewing where % in directory/file names is meant to be interpreted literally?
- etc. etc. etc.
If anyone wants to explore the wonderful world of mis-implemented copy-paste and drag-and-drop themselves, here's a little PyQt utility I wrote for inspecting the raw data and how PyQt interprets it while I was building my code and its test suite. I've only tested it under X11 on Linux, but it should theoretically work on Wayland, Windows, and macOS too.
(Tip: Firefox's Copy Image and Okular's option to copy the selection as an image produce an eye-opening list of offered image formats. I'm still trying to figure out what the image/pic offered by Okular is so I can generate a properly licensed dummy one for my test suite.)
Leave a comment: