microsoft / microsoft/playwright-java
[Bug]: Playwright does not recognize Pattern quotation escape sequence (\Q ... \E)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 1.6k
- Fork
- 298
- Merge medio
- 3g 2h
- PR unite (30g)
- 14
Descrizione
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)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal punto di ingresso Java Locator.FilterOptions.setHasText e riproduci le due asserzioni Pattern.compile sull’intestazione di playwright.dev. Traccia il modo in cui le espressioni regolari Java vengono trasferite al motore JavaScript del browser, quindi verifica che sia i pattern semplici sia quelli di Pattern.quote corrispondano allo stesso elemento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java, javascript
- Ambito
- testing-qa
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100