Tampermonkey / tampermonkey

Tampermonkey is the most popular userscript manager, with over 10 million users. It's available for Chrome, Microsoft Edge, Safari, Opera Next, and Firefox.
GNU General Public License v3.0
4.17k stars 416 forks source link

GM_download original server filename parsed wrong #2148

Open Owyn opened 1 month ago

Owyn commented 1 month ago

When I don't specify a filename for the gm_download and it tries to use the server one - it doesn't parse it properly, e.g. %20 - doesn't turn into spaces, you just remove % sign leaving 20 there and thus corrupting the filename

server filename which is given

file%20name.jpg

Expected Behavior

file name.jpg

Actual Behavior

file20name.jpg

Specifications

Script

Example script:

// ==UserScript==
// @name         Test for GM_download
// @namespace    http://tampermonkey.net/
// @version      2025
// @description  try to take over the world!
// @author       You
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @match        https://www.google.com.hk/*
// @match        https://www.google.com/*
// @grant        GM_download
// @include      https://rule34.paheal.net/post/view/13409
// ==/UserScript==

(function() {
    'use strict';

    document.querySelector('#main_image').addEventListener('click', function(){
        console.log("a click on the image");
        GM_download({
            "url": document.querySelector('#main_image').src,
            "name": null,
            "saveAs": true,
            "onload": function(e) {
                console.log("onload: %o", e);
            },
            "onerror": function(e) {
                console.log("onerror: %o", e);
            },
            "onprogress": function(e) {
                console.log("onprogress: %o", e);
            },
            "ontimeout ": function(e) {
                console.log("ontimeout : %o", e);
            }
        });
    });
})();

example url with an image to left click (it will do the gm_download) then compare it with the name it'd give you if you right-click -> save as it: https://rule34.paheal.net/post/view/13409

derjanb commented 2 weeks ago

Should be fixed at 5.3.6208 (crx|xpi in review)