Merge pull request #2778 from xmcclure/checked-build-updates-2
[mono.git] / mcs / class / System.Net.Http / System.Net.Http.Headers / ContentDispositionHeaderValue.cs
index a4d1ae275b478decfcf16103b66b7d4819a6e461..f80e50e41431ff0013d257f124aa2708867252fb 100644 (file)
@@ -120,9 +120,17 @@ namespace System.Net.Http.Headers
 
                public string Name {
                        get {
-                               return FindParameter ("name");
+                               var value = FindParameter ("name");
+
+                               if (value == null)
+                                       return null;
+
+                               return DecodeValue (value, false);
                        }
                        set {
+                               if (value != null)
+                                       value = EncodeBase64Value (value);
+
                                SetValue ("name", value);
                        }
                }
@@ -211,6 +219,10 @@ namespace System.Net.Http.Headers
 
                static string EncodeBase64Value (string value)
                {
+                       bool quoted = value.Length > 1 && value [0] == '"' && value [value.Length - 1] == '"';
+                       if (quoted)
+                               value = value.Substring (1, value.Length - 2);
+
                        for (int i = 0; i < value.Length; ++i) {
                                var ch = value[i];
                                if (ch > 127) {
@@ -220,7 +232,7 @@ namespace System.Net.Http.Headers
                                }
                        }
 
-                       if (!Lexer.IsValidToken (value))
+                       if (quoted || !Lexer.IsValidToken (value))
                                return "\"" + value + "\"";
 
                        return value;
@@ -245,6 +257,11 @@ namespace System.Net.Http.Headers
                                        continue;
                                }
 
+                               if (!Lexer.IsValidCharacter (ch) || ch == '*' || ch == '?' || ch == '%') {
+                                       sb.Append (Uri.HexEscape (ch));
+                                       continue;
+                               }
+
                                sb.Append (ch);
                        }
 
@@ -394,7 +411,7 @@ namespace System.Net.Http.Headers
 
                        switch (t.Kind) {
                        case Token.Type.SeparatorSemicolon:
-                               if (!NameValueHeaderValue.TryParseParameters (lexer, out parameters))
+                               if (!NameValueHeaderValue.TryParseParameters (lexer, out parameters, out t) || t != Token.Type.End)
                                        return false;
                                break;
                        case Token.Type.End: