Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for storage_state with lone surrogates #2261

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tests/async/test_browsercontext_storage_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import json
from pathlib import Path

from playwright.async_api import Browser, BrowserContext
from playwright.async_api import Browser, BrowserContext, Page
from tests.server import Server


async def test_should_capture_local_storage(context: BrowserContext) -> None:
Expand Down Expand Up @@ -99,3 +100,14 @@ async def test_should_round_trip_through_the_file(
cookie = await page2.evaluate("document.cookie")
assert cookie == "username=John Doe"
await context2.close()


async def test_should_serialiser_storage_state_with_lone_surrogates(
page: Page, context: BrowserContext, server: Server
) -> None:
await page.goto(server.EMPTY_PAGE)
await page.evaluate(
"""chars => window.localStorage.setItem('foo', String.fromCharCode(55934))"""
)
storage_state = await context.storage_state()
assert storage_state["origins"][0]["localStorage"][0]["value"] == chr(55934)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure python is totally fine with unpaired surrogates.

>>> print(chr(55934))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode character '\uda7e' in position 0: surrogates not allowed

Loading