Skip to content

Commit

Permalink
ShouldQuerySpecialCharElement
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyun0112 committed Nov 8, 2023
1 parent 510f493 commit ba83237
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Playwright.Tests/ElementHandleQuerySelectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ namespace Microsoft.Playwright.Tests;

public class ElementHandleQuerySelectorTests : PageTestEx
{
[PlaywrightTest()]
public async Task ShouldQuerySpecialCharElement()
{
await Page.SetContentAsync("<p title=\"曾全网封禁的《𝑭𝒂𝒍𝒍𝒊𝒏𝒈 𝑨𝒈𝒂𝒊𝒏》如今治愈了无数人的心灵\" class=\"title\">曾全网封禁的《𝑭𝒂𝒍𝒍𝒊𝒏𝒈 𝑨𝒈𝒂𝒊𝒏》如今治愈了无数人的心灵</p>");

var titleA = await Page.QuerySelectorAsync(".title");
var innerText = await titleA.InnerTextAsync();
Assert.AreEqual("曾全网封禁的《𝑭𝒂𝒍𝒍𝒊𝒏𝒈 𝑨𝒈𝒂𝒊𝒏》如今治愈了无数人的心灵", innerText);
}

[PlaywrightTest("elementhandle-query-selector.spec.ts", "should query existing element")]
public async Task ShouldQueryExistingElement()
{
Expand Down
21 changes: 20 additions & 1 deletion src/Playwright/Transport/Channels/ElementHandleChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright.Core;
using Microsoft.Playwright.Helpers;
Expand All @@ -49,7 +50,25 @@ internal override void OnMessage(string method, JsonElement? serverParams)
switch (method)
{
case "previewUpdated":
PreviewUpdated?.Invoke(this, serverParams.Value.GetProperty("preview").ToString());
var preview = string.Empty;
try
{
preview = serverParams.Value.GetProperty("preview").ToString();
}
catch
{
var matchResult = Regex.Match(serverParams.Value.ToString(), "\"preview\":\"(.*)\"");
if (matchResult.Success)
{
preview = matchResult.Groups[1].ToString();
}
else
{
preview = serverParams.Value.ToString();
}
}

PreviewUpdated?.Invoke(this, preview);
break;
}
}
Expand Down

0 comments on commit ba83237

Please sign in to comment.