diff --git a/src/SitemapParser.php b/src/SitemapParser.php index 4bea782..b4d46e4 100644 --- a/src/SitemapParser.php +++ b/src/SitemapParser.php @@ -146,7 +146,10 @@ public function parseRecursive($url) public function addToQueue(array $urlArray) { foreach ($urlArray as $url) { - $this->queue[] = $url; + $url = $this->urlEncode($url); + if ($this->urlValidate($url)) { + $this->queue[] = $url; + } } } @@ -173,10 +176,13 @@ public function getQueue() public function parse($url, $urlContent = null) { $this->clean(); - $this->currentURL = $url; + $this->currentURL = $this->urlEncode($url); + if (!$this->urlValidate($this->currentURL)) { + throw new Exceptions\SitemapParserException('Invalid URL'); + } $this->history[] = $this->currentURL; $response = is_string($urlContent) ? $urlContent : $this->getContent(); - if ($this->urlValidate($this->currentURL) && parse_url($this->currentURL, PHP_URL_PATH) === self::ROBOTSTXT_PATH) { + if (parse_url($this->currentURL, PHP_URL_PATH) === self::ROBOTSTXT_PATH) { $this->parseRobotstxt($response); return; }