subhra74 / xdm

Powerfull download accelerator and video downloader
https://xtremedownloadmanager.com/
GNU General Public License v2.0
6.62k stars 1.09k forks source link

can not handle filename correctly #1012

Open ttys3 opened 1 year ago

ttys3 commented 1 year ago

XDM is currently being re-written to be more user friendly and performant, please refer to (https://github.com/subhra74/xdm/discussions/768) for more information

PLEASE DO NOT JUST SAY "It does not work, or something not working etc." Provide enough relevent details so that the issue can be analyzed and reproduced easily

Describe the bug

can not handle filename correctly like:

Content-Disposition: attachment;filename*=utf-8''aaaa.rar; filename="aaaa.rar"

the final saved filename by xdm is aaaa.rar; filename="aaaa.rar" is wrong.

To Reproduce Steps to reproduce the behavior:

  1. download from microsoft sharepoint share file (must be sharepoint, onedrive can not reproduces this issue),

you will get header like Content-Disposition: attachment;filename*=utf-8''xxxx%2Erar;filename="xxxx.rar"

Expected behavior

filename should be aaaa.rar, not aaaa.rar; filename="aaaa.rar"

please complete the following information:

Additional context Add any other context about the problem here.

ttys3 commented 1 year ago

maybe related to

        public static string? GetContentDispositionFileName(string contentDisposition)
        {
            try
            {
                var r1 = new Regex(@"\s*filename\*\s*=\s*[^']*\'\s*\'(.*)");
                var r2 = new Regex("\\s*filename\\s*=\\s*\"([^\"]*)\"");
                var r3 = new Regex("filename\\s*=\\s*([^\"]+)");

                //var contentDisposition = response.Headers.Get("Content-Disposition");
                if (contentDisposition != null)
                {
                    Log.Debug("Trying to get filename from: " + contentDisposition);
                    foreach (var r in new Regex[] { r1, r2, r3 })
                    {
                        var m = r.Match(contentDisposition);
                        if (m.Success && m.Groups.Count >= 2)
                        {
                            return FileHelper.SanitizeFileName(Uri.UnescapeDataString(m.Groups[1].Value));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Debug(ex, ex.Message);
            }

            return null;
        }
ttys3 commented 1 year ago

PR submitted: https://github.com/subhra74/xdm/pull/1013