Skip to content

Commit d49e306

Browse files
committed
[DomCrawler] Fixed handling of relative query strings as links
1 parent a4451b4 commit d49e306

File tree

1 file changed

+14
-2
lines changed
  • src/Symfony/Component/DomCrawler

1 file changed

+14
-2
lines changed

src/Symfony/Component/DomCrawler/Link.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,23 @@ public function getUri()
8989
return $this->currentUri;
9090
}
9191

92-
// only an anchor or a query string
93-
if (in_array($uri[0], array('?', '#'))) {
92+
// only an anchor
93+
if ('#' === $uri[0]) {
9494
return $this->currentUri.$uri;
9595
}
9696

97+
// only a query string
98+
if ('?' === $uri[0] ) {
99+
$baseUri = $this->currentUri;
100+
101+
// remove the query string from the current uri
102+
if (false !== ($pos = strpos($this->currentUri, '?'))) {
103+
$baseUri = substr($this->currentUri, 0, strpos($this->currentUri, '?'));
104+
}
105+
106+
return $baseUri.$uri;
107+
}
108+
97109
// absolute path
98110
if ('/' === $uri[0]) {
99111
return preg_replace('#^(.*?//[^/]+)(?:\/.*)?$#', '$1', $this->currentUri).$uri;

0 commit comments

Comments
 (0)