Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DomCrawler] Make masterminds/html5 as a required dependency of DomCrawler #44170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions 12 src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Crawler implements \Countable, \IteratorAggregate
*/
private bool $isHtml = true;

private ?HTML5 $html5Parser;
private HTML5 $html5Parser;

/**
* @param \DOMNodeList|\DOMNode|\DOMNode[]|string|null $node A Node to use as the base for the crawling
Expand All @@ -67,7 +67,7 @@ public function __construct(\DOMNodeList|\DOMNode|array|string $node = null, str
{
$this->uri = $uri;
$this->baseHref = $baseHref ?: $uri;
$this->html5Parser = class_exists(HTML5::class) ? new HTML5(['disable_html_ns' => true]) : null;
$this->html5Parser = new HTML5(['disable_html_ns' => true]);
$this->cachedNamespaces = new \ArrayObject();

$this->add($node);
Expand Down Expand Up @@ -589,7 +589,7 @@ public function html(string $default = null): string
$node = $this->getNode(0);
$owner = $node->ownerDocument;

if (null !== $this->html5Parser && '<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
if ('<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
$owner = $this->html5Parser;
}

Expand All @@ -610,7 +610,7 @@ public function outerHtml(): string
$node = $this->getNode(0);
$owner = $node->ownerDocument;

if (null !== $this->html5Parser && '<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
if ('<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
$owner = $this->html5Parser;
}

Expand Down Expand Up @@ -1178,12 +1178,10 @@ private function parseHtmlString(string $content, string $charset): \DOMDocument

private function canParseHtml5String(string $content): bool
{
if (null === $this->html5Parser) {
return false;
}
if (false === ($pos = stripos($content, '<!doctype html>'))) {
return false;
}

$header = substr($content, 0, $pos);

return '' === $header || $this->isValidHtml5Heading($header);
Expand Down
9 changes: 3 additions & 6 deletions 9 src/Symfony/Component/DomCrawler/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
"require": {
"php": ">=8.1",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
"symfony/css-selector": "^5.4|^6.0",
"symfony/polyfill-mbstring": "~1.0",
"masterminds/html5": "^2.6"
tgalopin marked this conversation as resolved.
Show resolved Hide resolved
},
"conflict": {
"masterminds/html5": "<2.6"
"require-dev": {
"symfony/css-selector": "^5.4|^6.0"
},
"suggest": {
"symfony/css-selector": ""
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.