[DomCrawler] Invalid uri created from forms if base tag present
This commit is contained in:
parent
fedbf711a1
commit
dc57a7a5a7
@ -755,7 +755,7 @@ class Crawler extends \SplObjectStorage
|
|||||||
throw new \InvalidArgumentException('The current node list is empty.');
|
throw new \InvalidArgumentException('The current node list is empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = new Form($this->getNode(0), $this->uri, $method);
|
$form = new Form($this->getNode(0), $this->uri, $method, $this->baseHref);
|
||||||
|
|
||||||
if (null !== $values) {
|
if (null !== $values) {
|
||||||
$form->setValues($values);
|
$form->setValues($values);
|
||||||
|
@ -33,20 +33,27 @@ class Form extends Link implements \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
private $fields;
|
private $fields;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $baseHref;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param \DOMNode $node A \DOMNode instance
|
* @param \DOMNode $node A \DOMNode instance
|
||||||
* @param string $currentUri The URI of the page where the form is embedded
|
* @param string $currentUri The URI of the page where the form is embedded
|
||||||
* @param string $method The method to use for the link (if null, it defaults to the method defined by the form)
|
* @param string $method The method to use for the link (if null, it defaults to the method defined by the form)
|
||||||
|
* @param string $baseHref The URI of the <base> used for relative links, but not for empty action
|
||||||
*
|
*
|
||||||
* @throws \LogicException if the node is not a button inside a form tag
|
* @throws \LogicException if the node is not a button inside a form tag
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function __construct(\DOMNode $node, $currentUri, $method = null)
|
public function __construct(\DOMNode $node, $currentUri, $method = null, $baseHref = null)
|
||||||
{
|
{
|
||||||
parent::__construct($node, $currentUri, $method);
|
parent::__construct($node, $currentUri, $method);
|
||||||
|
$this->baseHref = $baseHref;
|
||||||
|
|
||||||
$this->initialize();
|
$this->initialize();
|
||||||
}
|
}
|
||||||
@ -442,6 +449,10 @@ class Form extends Link implements \ArrayAccess
|
|||||||
$this->addField($node);
|
$this->addField($node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->baseHref && '' !== $this->node->getAttribute('action')) {
|
||||||
|
$this->currentUri = $this->baseHref;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addField(\DOMNode $node)
|
private function addField(\DOMNode $node)
|
||||||
|
@ -853,9 +853,12 @@ HTML;
|
|||||||
public function getBaseTagWithFormData()
|
public function getBaseTagWithFormData()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
array('https://base.com/', 'link/', 'https://base.com/link/', 'https://base.com/link/', '<base> tag does work with a path and relative form action'),
|
||||||
array('/basepath', '/registration', 'http://domain.com/registration', 'http://domain.com/registration', '<base> tag does work with a path and form action'),
|
array('/basepath', '/registration', 'http://domain.com/registration', 'http://domain.com/registration', '<base> tag does work with a path and form action'),
|
||||||
array('/basepath', '', 'http://domain.com/registration', 'http://domain.com/registration', '<base> tag does work with a path and empty form action'),
|
array('/basepath', '', 'http://domain.com/registration', 'http://domain.com/registration', '<base> tag does work with a path and empty form action'),
|
||||||
|
array('http://base.com/', '/registration', 'http://base.com/registration', 'http://domain.com/registration', '<base> tag does work with a URL and form action'),
|
||||||
array('http://base.com', '', 'http://domain.com/path/form', 'http://domain.com/path/form', '<base> tag does work with a URL and an empty form action'),
|
array('http://base.com', '', 'http://domain.com/path/form', 'http://domain.com/path/form', '<base> tag does work with a URL and an empty form action'),
|
||||||
|
array('http://base.com/path', '/registration', 'http://base.com/registration', 'http://domain.com/path/form', '<base> tag does work with a URL and form action'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user