Skip to content

Commit

Permalink
#594 don't URL-encode cookie values
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed May 3, 2021
1 parent be6839c commit f9d930b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
6 changes: 0 additions & 6 deletions Test/Flurl.Test/Http/CookieTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ public void cannot_change_cookie_after_adding_to_jar() {
Assert.Throws<Exception>(() => cookie.Secure = false);
}

[Test]
public void url_decodes_cookie_value() {
var cookie = CookieCutter.ParseResponseHeader("https://cookies.com", "x=one%3A%20for%20the%20money");
Assert.AreEqual("one: for the money", cookie.Value);
}

[Test]
public void unquotes_cookie_value() {
var cookie = CookieCutter.ParseResponseHeader("https://cookies.com", "x=\"hello there\"" );
Expand Down
6 changes: 3 additions & 3 deletions src/Flurl.Http/CookieCutter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class CookieCutter
if (string.IsNullOrEmpty(headerValue)) yield break;

foreach (var pair in GetPairs(headerValue))
yield return (pair.Name, Url.Decode(pair.Value, false));
yield return (pair.Name, pair.Value);
}

/// <summary>
Expand All @@ -34,7 +34,7 @@ public static FlurlCookie ParseResponseHeader(string url, string headerValue) {
FlurlCookie cookie = null;
foreach (var pair in GetPairs(headerValue)) {
if (cookie == null)
cookie = new FlurlCookie(pair.Name, Url.Decode(pair.Value.Trim('"'), false), url, DateTimeOffset.UtcNow);
cookie = new FlurlCookie(pair.Name, pair.Value.Trim('"'), url, DateTimeOffset.UtcNow);

// ordinal string compare is both safest and fastest
// https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings#recommendations-for-string-usage
Expand Down Expand Up @@ -72,7 +72,7 @@ public static string ToRequestHeader(IEnumerable<(string Name, string Value)> co
if (cookies?.Any() != true) return null;

return string.Join("; ", cookies.Select(c =>
$"{Url.Encode(c.Name)}={Url.Encode(c.Value)}"));
$"{c.Name}={c.Value}"));
}

/// <summary>
Expand Down

0 comments on commit f9d930b

Please sign in to comment.