-
Notifications
You must be signed in to change notification settings - Fork 289
Open
Description
Version
1.52.0
Steps to reproduce
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;
class Program
{
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true });
var page = await browser.NewPageAsync();
// .NET regex with inline (?i)
var regex = new Regex(@"(?i).+\.css$");
// Throws: Invalid regular expression: /(?i).+\.css$/: Invalid group
await page.RouteAsync(regex, route => route.ContinueAsync());
await browser.CloseAsync();
}
}
Expected behavior
Playwright.NET should honour the PCRE / .NET regex.
At the very least, i, m and s.
Actual behavior
It doesn't.
Additional context
The regex @"(?i).+\.css$" includes the modifier (?i) which is the same as RegexOptions.IgnoreCase. It is preferable as that is embedded in the regex itself and can be easily transported across system boundaries as a simple string. It is standard PCRE.
JS is not PCRE compliant though, and requires the syntax /.+\.css$/i. For some reason Playwright is extracting the regex from the Regex instance and passing it directly to the browser, without checking for modifiers (and translating them to JS regex).
Environment
- Operating System: Ubuntu 24
- CPU: amd64
- Browser: All
- .NET Version: v8
Metadata
Metadata
Assignees
Labels
No labels