// Returns input for decoding failures, as the content might not be encoded. private static string EncodeAndQuoteMime(string input) { string result = input; bool needsQuotes = false; // Remove bounding quotes, they'll get re-added later. if (IsQuoted(result)) { result = result.Substring(1, result.Length - 2); needsQuotes = true; } if (result.Contains('"')) // Only bounding quotes are allowed. { throw new ArgumentException(SR.Format(CultureInfo.InvariantCulture, SR.net_http_headers_invalid_value, input)); } else if (HeaderUtilities.ContainsNonAscii(result)) { needsQuotes = true; // Encoded data must always be quoted, the equals signs are invalid in tokens. result = EncodeMime(result); // =?utf-8?B?asdfasdfaesdf?= } else if (!needsQuotes && HttpRuleParser.GetTokenLength(result, 0) != result.Length) { needsQuotes = true; } if (needsQuotes) { // Re-add quotes "value". result = "\"" + result + "\""; } return(result); }
private static string EncodeAndQuoteMime(string input) { string input1 = input; bool flag = false; if (ContentDispositionHeaderValue.IsQuoted((ReadOnlySpan <char>)input1)) { input1 = input1.Substring(1, input1.Length - 2); flag = true; } if (input1.Contains('"')) { throw new ArgumentException(SR.Format((IFormatProvider)CultureInfo.InvariantCulture, SR.net_http_headers_invalid_value, (object)input)); } if (HeaderUtilities.ContainsNonAscii(input1)) { flag = true; input1 = ContentDispositionHeaderValue.EncodeMime(input1); } else if (!flag && HttpRuleParser.GetTokenLength(input1, 0) != input1.Length) { flag = true; } if (flag) { input1 = "\"" + input1 + "\""; } return(input1); }