Skip to content

Commit 5c3beee

Browse files
authored
Fix resolver not formatting properly when selector has a closing parenthesis (#1184)
* fix: regex pattern selecting closing parenthesis * test: added case for selector with closing parenthesis
1 parent 4de0ec1 commit 5c3beee

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/ElementResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function format($selector)
410410
);
411411

412412
if (Str::startsWith($selector, '@') && $selector === $originalSelector) {
413-
$selector = preg_replace('/@(\S+)/', '['.Dusk::$selectorHtmlAttribute.'="$1"]', $selector);
413+
$selector = preg_replace('/@([^\s\)]+)/', '['.Dusk::$selectorHtmlAttribute.'="$1"]', $selector);
414414
}
415415

416416
return trim($this->prefix.' '.$selector);

tests/Unit/ElementResolverTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public function test_format_correctly_formats_selectors()
150150
$this->assertSame('prefix [dusk="missing-element"] > div', $resolver->format('@missing-element > div'));
151151
}
152152

153+
public function test_format_does_not_capture_closing_parenthesis_in_dusk_selector()
154+
{
155+
$resolver = new ElementResolver(new stdClass, 'prefix');
156+
$this->assertSame('prefix [dusk="products"] div:nth-child(2 of [dusk="product"])', $resolver->format('@products div:nth-child(2 of @product)'));
157+
}
158+
153159
public function test_find_by_id_with_colon()
154160
{
155161
$driver = m::mock(stdClass::class);

0 commit comments

Comments
 (0)