OSDN Git Service

na-get-lib, a4ab378a911e444c1d35e49e4de87bc1ea86755b でのミスを修正。
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands.SubTask / DownloadSubTask.cs
index 891d50e..c1ff3e4 100644 (file)
@@ -349,8 +349,17 @@ namespace NaGet.SubCommands.SubTask
                        HttpWebResponse httpresp = response as HttpWebResponse;
                        if (httpresp != null) {
                                string contentDisposition = httpresp.Headers["Content-Disposition"];
-                               
                                if (! string.IsNullOrEmpty(contentDisposition)) {
+                                       // おかしな Content-Disposition ヘッダ向け
+                                       // attachment と書いていないでいきなり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)) {