8000 bug #11219 [DomCrawler] properly handle buttons with single and doubl… · symfony/symfony@1045adf · GitHub
[go: up one dir, main page]

Skip to content

Commit 1045adf

Browse files
committed
bug #11219 [DomCrawler] properly handle buttons with single and double quotes insid... (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [DomCrawler] properly handle buttons with single and double quotes insid... | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11151 | License | MIT | Doc PR | Commits ------- cbbdbe4 [DomCrawler] properly handle buttons with single and double quotes inside the name attribute
2 parents 84be8de + cbbdbe4 commit 1045adf

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,8 @@ public function selectButton($value)
660660
{
661661
$translate = 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")';
662662
$xpath = sprintf('descendant-or-self::input[((contains(%s, "submit") or contains(%s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %s)) ', $translate, $translate, static::xpathLiteral(' '.$value.' ')).
663-
sprintf('or (contains(%s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %s)) or @id="%s" or @name="%s"] ', $translate, static::xpathLiteral(' '.$value.' '), $value, $value).
664-
sprintf('| descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %s) or @id="%s" or @name="%s"]', static::xpathLiteral(' '.$value.' '), $value, $value);
663+
sprintf('or (contains(%s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %s)) or @id=%s or @name=%s] ', $translate, static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value), static::xpathLiteral($value)).
664+
sprintf('| descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %s) or @id=%s or @name=%s]', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value), static::xpathLiteral($value));
665665

666666
return $this->filterRelativeXPath($xpath);
667667
}

src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,48 @@ public function testSelectButton()
466466
$this->assertEquals(1, $crawler->selectButton('FooBarName')->count(), '->selectButton() selects buttons with form attribute too');
467467
}
468468

469+
public function testSelectButtonWithSingleQuotesInNameAttribute()
470+
{
471+
$html = <<<HTML
472+
<!DOCTYPE html>
473+
<html lang="en">
474+
<body>
475+
<div id="action">
476+
<a href="/index.php?r=site/login">Login</a>
477+
</div>
478+
<form id="login-form" action="/index.php?r=site/login" method="post">
479+
<button type="submit" name="Click 'Here'">Submit</button>
480+
</form>
481+
</body>
482+
</html>
483+
HTML;
484+
485+
$crawler = new Crawler($html);
486+
487+
$this->assertCount(1, $crawler->selectButton('Click \'Here\''));
488+
}
489+
490+
public function testSelectButtonWithDoubleQuotesInNameAttribute()
491+
{
492+
$html = <<<HTML
493+
<!DOCTYPE html>
494+
<html lang="en">
495+
<body>
496+
<div id="action">
497+
<a href="/index.php?r=site/login">Login</a>
498+
</div>
499+
<form id="login-form" action="/index.php?r=site/login" method="post">
500+
<button type="submit" name='Click "Here"'>Submit</button>
501+
</form>
502+
</body>
503+
</html>
504+
HTML;
505+
506+
$crawler = new Crawler($html);
507+
508+
$this->assertCount(1, $crawler->selectButton('Click "Here"'));
509+
}
510+
469511
public function testLink()
470512
{
471513
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectLink('Foo');

0 commit comments

Comments
 (0)
0