microsoft / microsoft/playwright-java

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

Abierto
#1,709 2 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

P3-collecting-feedback
Lenguaje dominante
Java
Estrellas
1.6k
Forks
298
Merge medio
3 d 2 h
PR fusionados (30 d)
14

Descripción

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)

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el punto de entrada Java Locator.FilterOptions.setHasText y reproduce las dos aserciones de Pattern.compile contra el encabezado de playwright.dev. Traza cómo las expresiones regulares de Java se transfieren al motor JavaScript del navegador y, después, verifica que tanto los patrones simples como los patrones de Pattern.quote coinciden con el mismo elemento.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java, javascript
Área
testing-qa
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.