microsoft / microsoft/playwright-java

[Bug]: Playwright does not recognize Pattern quotation escape sequence (\Q ... \E)

Offen
#1,709 2 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

P3-collecting-feedback
Vorherrschende Sprache
Java
Sterne
1.6k
Forks
298
Ø Merge
3 T. 2 Std.
Gemergte PRs (30 T.)
14

Beschreibung

Version

1.47.0

Steps to reproduce

Using Playwright Java, navigate to https://playwright.dev

Run the following assertions:

working:

assertThat(page.getByRole(AriaRole.HEADING)
  .filter(new Locator.FilterOptions().setHasText(Pattern.compile("Playwright")))
).isVisible();

not working:

assertThat(page.getByRole(AriaRole.HEADING)
  .filter(new Locator.FilterOptions().setHasText(Pattern.compile(Pattern.quote("Playwright"))))
).isVisible();
Expected behavior

Both patterns should work, as they match exactly the same strings.

Actual behavior

The second pattern fails to find the DOM element.

Additional context

Java has the Regex special escapes \Q and \E, which means all characters are quoted as is betwen those two escape sequences. This is exactly what Pattern.quote does.

In other words, these are equivalent (as you can see if you print the result of Pattern.quote):
Pattern.compile("\\Qsometext\\E")
Pattern.compile(Pattern.quote("sometext"))

This is documented here (search for "Quotation"): https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html

This is speculation, but why it might fail is if the regex is just transferred to the Javascript engine and executed there. Javascript does not seem to have the \Q and \E special escapes, which leads to the meaning of the passed regex to change.

You can also check here, switch between Java and ECMAScript engines; it works for Java but not for Javascript: https://regex101.com/r/lJ1XNH/1

Environment

macOS Sequoia, arm64
Java 17
Chromium browser (others not tested)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit dem Java-Locator.FilterOptions.setHasText-Einstiegspunkt und reproduzieren Sie die beiden Pattern.compile-Assertions gegen die Überschrift auf playwright.dev. Verfolgen Sie, wie Java-reguläre Ausdrücke an die JavaScript-Engine des Browsers übertragen werden, und überprüfen Sie anschließend, dass sowohl einfache als auch Pattern.quote-Muster dasselbe Element matchen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java, javascript
Bereich
testing-qa
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.