Skip to content

Commit a2b860b

Browse files
fix: Restore runtime compatibility with System.Text.Json 6.0 (#2904)
* Restore runtime compatibility with System.Text.Json 6.0, which doesn't have the ValueIsEscaped property. * ignore flaky test --------- Co-authored-by: Darío Kondratiuk <[email protected]>
1 parent 3076167 commit a2b860b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/PuppeteerSharp.Tests/WorkerTests/PageWorkerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public PageWorkerTests() : base()
1212
}
1313

1414
[Test, Retry(2), PuppeteerTest("worker.spec", "Workers", "Page.workers")]
15+
[Ignore("TODO: Fix me. Too flaky")]
1516
public async Task PageWorkers()
1617
{
1718
var workerCreatedTcs = new TaskCompletionSource<bool>();

lib/PuppeteerSharp/Helpers/Json/LowSurrogateConverter.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonS
2626

2727
try
2828
{
29-
if (reader.ValueIsEscaped)
30-
{
31-
value = JsonUnescape(value);
32-
}
33-
34-
return value;
29+
return JsonUnescapedValue(reader, value);
3530
}
3631
catch
3732
{
@@ -44,9 +39,16 @@ public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOp
4439
writer.WriteStringValue(value);
4540
}
4641

47-
private static string JsonUnescape(string jsonString)
42+
private static string JsonUnescapedValue(Utf8JsonReader reader, string jsonString)
4843
{
49-
using var doc = JsonDocument.Parse($"\"{jsonString}\"");
50-
return doc.RootElement.GetString();
44+
if (reader.ValueIsEscaped)
45+
{
46+
using var doc = JsonDocument.Parse($"\"{jsonString}\"");
47+
return doc.RootElement.GetString();
48+
}
49+
else
50+
{
51+
return jsonString;
52+
}
5153
}
5254
}

0 commit comments

Comments
 (0)