OSDN Git Service

na-get-lib,ファイルダウンロードで attachment;filename= のようにセミコロン後にスペースがない場合の対応
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands.SubTask / DownloadSubTask.cs
index 891d50e..74cd2a9 100644 (file)
@@ -351,6 +351,16 @@ namespace NaGet.SubCommands.SubTask
                                string contentDisposition = httpresp.Headers["Content-Disposition"];
                                
                                if (! string.IsNullOrEmpty(contentDisposition)) {
+                                       // おかしな Content-Disposition ヘッダ向け
+                                       //(Content-Disposition: filename=\"...\" に attachment; を補って RFC1806 に準拠させる)
+                                       if (System.Text.RegularExpressions.Regex.IsMatch(contentDisposition, @" *filename=", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) {
+                                               contentDisposition = "attachment; " + contentDisposition;
+                                       }
+                                       // "atachment;filename=\""のようにセミコロンの後ろにスペースがない場合、それを補充する
+                                       if (System.Text.RegularExpressions.Regex.IsMatch(contentDisposition, @";[^ ]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) {
+                                               contentDisposition = string.Join("; ", System.Text.RegularExpressions.Regex.Split(contentDisposition, @"; *"));
+                                       }
+                                       
                                        try {
                                                ContentDisposition parser = new ContentDisposition(contentDisposition);
                                                if (! string.IsNullOrEmpty(parser.FileName)) {