Skip to content

fix(evaluate): serialize and parse RegExp values - #3189

Open
FadeHack (FadeHack) wants to merge 1 commit into
microsoft:mainfrom
FadeHack:fix-3188
Open

fix(evaluate): serialize and parse RegExp values#3189
FadeHack (FadeHack) wants to merge 1 commit into
microsoft:mainfrom
FadeHack:fix-3188

Conversation

@FadeHack

@FadeHack FadeHack (FadeHack) commented Aug 26, 2026

Copy link
Copy Markdown

serialize_value() has no branch for re.Pattern, so passing a compiled pattern to evaluate() silently sends undefined. parse_value() has no branch for "r", so a RegExp coming back from the page reaches the caller as the raw wire dict instead of a pattern:

>>> page.evaluate("(v) => String(v)", re.compile(r"a\d+", re.I))
'undefined'
>>> page.evaluate("() => /a\\d+/gi")
{'r': {'p': 'a\\d+', 'f': 'gi'}}

The protocol already carries regexes as {r: {p, f}} and the driver implements both sides, so this just adds the two missing branches on the Python side. playwright-dotnet does the same in EvaluateArgumentValueConverter.cs.

Flags reuse the existing escape_regex_flags() helper. On the way back, the JavaScript-only flags (g, y, d, u, v) have no re equivalent and are dropped.

Fixes #3188

serialize_value() had no branch for re.Pattern, so a compiled pattern
passed to evaluate() was silently sent as undefined. parse_value() had
no branch for "r", so a RegExp coming back from the page surfaced as the
raw wire dict instead of a pattern.

Both directions now use the {r: {p, f}} form the driver already
implements. Flags map through the existing escape_regex_flags() helper;
on the way back the JavaScript-only flags (g, y, d, u, v) have no re
equivalent and are dropped.

Fixes: microsoft#3188
@FadeHack

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RegExp values are not serialized by evaluate(), and returned RegExps leak internal protocol JSON

1 participant