Skip to content

Commit

Permalink
Modified ParamaterList.TryParse() to handle quoted rfc2231-encoded pa…
Browse files Browse the repository at this point in the history
…ram values

Fixes issue #239
  • Loading branch information
jstedfast committed May 5, 2016
1 parent 7e6baa3 commit ccc2201
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions MimeKit/ParameterList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,17 @@ internal static bool TryParse (ParserOptions options, byte[] text, ref int index
}
hex.Reset ();
} else if (param.Encoded) {
// Note: param value is not supposed to be quoted, but issue #239 illustrates
// that this can happen in the wild. Hopefully we will not need to worry
// about quoted-pairs.
if (length >= 2 && buffer[startIndex] == (byte) '"') {
if (buffer[startIndex + length - 1] == (byte) '"')
length--;

startIndex++;
length--;
}

value = DecodeRfc2231 (out encoding, ref decoder, hex, buffer, startIndex, length, true);
method = ParameterEncodingMethod.Rfc2231;
hex.Reset ();
Expand Down
11 changes: 11 additions & 0 deletions UnitTests/ContentDispositionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ public void TestChineseFilename2047 ()
Assert.AreEqual ("GB18030", param.Encoding.HeaderName, "The filename encoding did not match.");
}

[Test]
public void TestIssue239 ()
{
const string text = " attachment; size=1049971;\n\tfilename*=\"utf-8''SBD%20%C5%A0kodov%C3%A1k%2Ejpg\"";
const string expected = "SBD Škodovák.jpg";
ContentDisposition disposition;

Assert.IsTrue (ContentDisposition.TryParse (text, out disposition), "Failed to parse Content-Disposition");
Assert.AreEqual (expected, disposition.FileName, "The filename value does not match.");
}

[Test]
public void TestFormData ()
{
Expand Down

0 comments on commit ccc2201

Please sign in to comment.