-
-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deserialization exception when retrieving cookie with PartitionKe…
…y set (#2783) * Fix incorrect CookieParam.PartitionKey type which caused deserialization exceptions * Reimplement fix based on upstream solution * Delete CookiePartitionKey * remove nullable and bump version --------- Co-authored-by: Darío Kondratiuk <dariokondratiuk@gmail.com>
- Loading branch information
Showing
3 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lib/PuppeteerSharp/Helpers/Json/CookiePartitionKeyConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PuppeteerSharp.Helpers.Json | ||
{ | ||
internal sealed class CookiePartitionKeyConverter : JsonConverter<string> | ||
{ | ||
/// <inheritdoc cref="JsonConverter"/> | ||
public override bool CanConvert(Type objectType) => typeof(string).IsAssignableFrom(objectType); | ||
|
||
/// <inheritdoc cref="JsonConverter"/> | ||
public override string? Read( | ||
ref Utf8JsonReader reader, | ||
Type objectType, | ||
JsonSerializerOptions options) | ||
{ | ||
JsonNode? node = JsonNode.Parse(ref reader); | ||
|
||
return node?["topLevelSite"]?.GetValue<string>() ?? null; | ||
} | ||
|
||
/// <inheritdoc cref="JsonConverter"/> | ||
public override void Write( | ||
Utf8JsonWriter writer, | ||
string value, | ||
JsonSerializerOptions options) | ||
{ | ||
if (value != null && writer != null) | ||
{ | ||
writer.WriteStartObject("partitionKey"); | ||
writer.WriteString("topLevelSite", value); | ||
writer.WriteBoolean("hasCrossSiteAncestor", false); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters