Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not handle filename correctly #1012

Open
ttys3 opened this issue Mar 20, 2023 · 2 comments
Open

can not handle filename correctly #1012

ttys3 opened this issue Mar 20, 2023 · 2 comments

Comments

@ttys3
Copy link

ttys3 commented Mar 20, 2023

XDM is currently being re-written to be more user friendly and performant, please refer to (#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:

  • OS: Linux
  • Browser chrome
  • XDM addon XDM Integration Module 3.3
  • XDM Version 8.0.25 beta

Additional context
Add any other context about the problem here.

@ttys3
Copy link
Author

ttys3 commented Mar 20, 2023

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
Copy link
Author

ttys3 commented Mar 21, 2023

PR submitted: #1013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant