Skip to content

Commit

Permalink
[DomCrawler] Fixed URIs being incorrectly generated
Browse files Browse the repository at this point in the history
When the path is not ending with a slash and the form/link has only ?get=params then the last bit of the path was incorrectly stripped
  • Loading branch information
Seldaek authored and fabpot committed Sep 3, 2010
1 parent a6da0fb commit 1719bfb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/Symfony/Component/DomCrawler/Crawler.php
Expand Up @@ -567,10 +567,6 @@ protected function parseUri($uri)

$path = parse_url($uri, PHP_URL_PATH);

if ('/' !== substr($path, -1)) {
$path = substr($path, 0, strrpos($path, '/') + 1);
}

return array(preg_replace('#^(.*?//[^/]+)\/.*$#', '$1', $uri), $path);
}

Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -176,8 +176,13 @@ public function getUri($absolute = true)
$uri .= $sep.$queryString;
}

$path = $this->path;
if ('?' !== substr($uri, 0, 1) && '/' !== substr($path, -1)) {
$path = substr($path, 0, strrpos($path, '/') + 1);
}

if ($uri && '/' !== $uri[0] && !$urlHaveScheme) {
$uri = $this->path.$uri;
$uri = $path.$uri;
}

if ($absolute && null !== $this->host && !$urlHaveScheme) {
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/DomCrawler/Link.php
Expand Up @@ -67,8 +67,13 @@ public function getUri($absolute = true)
$uri = $this->node->getAttribute('href');
$urlHaveScheme = 'http' === substr($uri, 0, 4);

$path = $this->path;
if ('?' !== substr($uri, 0, 1) && '/' !== substr($path, -1)) {
$path = substr($path, 0, strrpos($path, '/') + 1);
}

if ($uri && '/' !== $uri[0] && !$urlHaveScheme) {
$uri = $this->path.$uri;
$uri = $path.$uri;
}

if ($absolute && null !== $this->host && !$urlHaveScheme) {
Expand Down

0 comments on commit 1719bfb

Please sign in to comment.