From 1719bfb871e1f923185efda47a319385c2f5a793 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 2 Sep 2010 18:56:55 +0200 Subject: [PATCH] [DomCrawler] Fixed URIs being incorrectly generated 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 --- src/Symfony/Component/DomCrawler/Crawler.php | 4 ---- src/Symfony/Component/DomCrawler/Form.php | 7 ++++++- src/Symfony/Component/DomCrawler/Link.php | 7 ++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index e6746615de..5a521b1d27 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -567,10 +567,6 @@ class Crawler extends \SplObjectStorage $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); } diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index 287873e060..a45015196b 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -176,8 +176,13 @@ class Form implements \ArrayAccess $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) { diff --git a/src/Symfony/Component/DomCrawler/Link.php b/src/Symfony/Component/DomCrawler/Link.php index 82dd5c79ee..c789a7da2c 100644 --- a/src/Symfony/Component/DomCrawler/Link.php +++ b/src/Symfony/Component/DomCrawler/Link.php @@ -67,8 +67,13 @@ class Link $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) {