Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/dom-crawler
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.2.12
Choose a base ref
...
head repository: symfony/dom-crawler
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.3.0
Choose a head ref
  • 19 commits
  • 16 files changed
  • 11 contributors

Commits on Dec 9, 2022

  1. Copy the full SHA
    5786d2c View commit details

Commits on Dec 22, 2022

  1. Merge branch '6.2' into 6.3

    * 6.2:
      Fix integration test gha
      Update RedisTrait.php
      Use static methods inside data providers
      [VarExporter] Fix exporting classes with __unserialize() but not __serialize()
      [Validator] Fix IBAN format for Tunisia and Mauritania
      [Workflow] Allow spaces in place names so the PUML dump doesn't break
      [VarExporter] Generate proxies for static abstract methods
      [SecurityBundle] Prevent RuntimeException "Impossible to access an attribute ("security_enabled") on a null variable."
    nicolas-grekas committed Dec 22, 2022
    Copy the full SHA
    9b37627 View commit details

Commits on Jan 1, 2023

  1. Merge branch '6.2' into 6.3

    * 6.2:
      Bump LICENSE year
      Bump LICENSE year
      Fix LICENSE year
      Bump license year to 2023
      Fix CS
      Fix CS
    fabpot committed Jan 1, 2023
    Copy the full SHA
    9e4f9af View commit details

Commits on Jan 11, 2023

  1. [DomCrawler] Add argument $normalizeWhitespace to `Crawler::innerTe…

    …xt()` and make it return the first non-empty text
    otsch authored and nicolas-grekas committed Jan 11, 2023
    Copy the full SHA
    0c005b9 View commit details

Commits on Jan 13, 2023

  1. Copy the full SHA
    923521a View commit details
  2. minor #48793 Leverage arrow function syntax for closure (tigitz)

    This PR was merged into the 6.3 branch.
    
    Discussion
    ----------
    
    Leverage arrow function syntax for closure
    
    | Q             | A
    | ------------- | ---
    | Branch?       | 6.3
    | Bug fix?      | no
    | New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
    | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
    | Tickets       | Fix #47658 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
    | License       | MIT
    | Doc PR        | <!-- required for new features -->
    
    Rationale in the RFC [here](https://wiki.php.net/rfc/arrow_functions_v2#introduction)
    
    It's also notable that using arrow function syntax rather than the classic one has been enforced in the past by symfony core member: symfony/symfony#48069 (comment)
    
    So this PR would be consistent.
    
    Commits
    -------
    
    f5802d3a2a Leverage arrow function syntax for closure
    nicolas-grekas committed Jan 13, 2023
    Copy the full SHA
    5eb8c0d View commit details

Commits on Jan 20, 2023

  1. Merge branch '6.2' into 6.3

    * 6.2:
      Update ComposerPlugin.php
      [Notifier] [OvhCloud] handle invalid receiver
      [Security] Return default value instead of deferring to lower prio resolvers when using #[CurrentUser] and no user is found
      [Cache] fix collecting cache stats when nesting computations
      [VarDumper] Fix JS to expand / collapse
      [Validator] Fix Email validator logic
      Fix user_identifier support after username has been deprecated in favor of it.
      [Tests] Remove `$this` occurrences in future static data providers
      [PropertyInfo] Fixes constructor extractor for mixed type
      use method_exists() instead of catching reflection exceptions
    nicolas-grekas committed Jan 20, 2023
    Copy the full SHA
    9db7195 View commit details

Commits on Feb 2, 2023

  1. Merge branch '6.2' into 6.3

    * 6.2:
      Fix LICENSE year
      Fix LICENSE CI check
      [Notifier] Mention Prisma Media as backer of v6.2
      fixes retrieving multiple values for extra fields
      Clarifies when to update UPGRADE-7.0.md
      [String] Remove duplicates in fold maps
      fail with a meaningful error when a needed package is missing
      [6.2] Remove mentions of v6.1 backers
      [Translation] Crowdin renewed their sponsorship for v6.2
      [DependencyInjection] Fix combinatory explosion when autowiring union and intersection types
      Update license years (last time)
      [Tests] New iteration of removing `$this` occurrences in future static data providers
    fabpot committed Feb 2, 2023
    Copy the full SHA
    15f2b48 View commit details

Commits on Feb 7, 2023

  1. Copy the full SHA
    70f01db View commit details

Commits on Feb 11, 2023

  1. Merge branch '6.2' into 6.3

    * 6.2:
      Fix merge
      Fix merge
      [FrameworkBundle] Improve error message in MicroKernelTrait when using deprecated configureRoutes(RouteCollectionBuilder) with symfony/routing >= 6.0
      Add warning about Symfony 5.2 changing pcntl_async_signals
      [Tests] Fix static calls and Mock var annotation
      [FrameworkBundle] Fix checkboxes check assertions
      [Notifier][WebProfilerBundle] Ignore messages whose `getNotification` returns `null`
      [HttpClient] Fix over-encoding of URL parts to match browser's behavior
      Fix Psalm job
      Revert "[HttpClient] Add support for "friendsofphp/well-known-implementations""
      [HttpClient] Fix data collector
      [Tests] Migrate tests to static data providers
      [Semaphore] Fix test
      Fix: Split and clean up tests
      Remove unused data provider
      [Form] Check for `RepeatedType` child in `PasswordHasherListener`
      add Sender to the list of bypassed headers
    xabbuh committed Feb 11, 2023
    Copy the full SHA
    c2f9688 View commit details

Commits on Feb 13, 2023

  1. Add void return types

    wouterj authored and nicolas-grekas committed Feb 13, 2023
    Copy the full SHA
    8f24248 View commit details

Commits on Feb 14, 2023

  1. Merge branch '6.2' into 6.3

    * 6.2:
      Fix merge
      Migrate to `static` data providers using `rector/rector`
    nicolas-grekas committed Feb 14, 2023
    Copy the full SHA
    3d3f1f4 View commit details

Commits on Feb 16, 2023

  1. Merge branch '6.2' into 6.3

    * 6.2:
      CS fix
      Fix test provider
    nicolas-grekas committed Feb 16, 2023
    Copy the full SHA
    d58c22d View commit details

Commits on Mar 6, 2023

  1. Copy the full SHA
    68800eb View commit details

Commits on Mar 9, 2023

  1. Merge branch '6.2' into 6.3

    * 6.2:
      [Security] remove deprecated conditions in supports and authenticate methods from AccessListener class
      [Tests] Replace `setMethods()` by `onlyMethods()` and `addMethods()`
    nicolas-grekas committed Mar 9, 2023
    Copy the full SHA
    64a4ec5 View commit details

Commits on Mar 13, 2023

  1. Copy the full SHA
    207c5e2 View commit details

Commits on Apr 11, 2023

  1. Merge branch '6.2' into 6.3

    * 6.2:
      Avoid call on null
      [Notifier] Document Firebase options object in readme
      [ErrorHandler] Fix sending Vary header with SerializerErrorRenderer
      Fix intl data tests
      Improve the description of the Intl component
      [DoctrineBridge] fix issue with missing stopwatch events
      [HttpClient] Fix canceling MockResponse
    nicolas-grekas committed Apr 11, 2023
    Copy the full SHA
    a91111a View commit details

Commits on Apr 21, 2023

  1. Copy the full SHA
    321d4f7 View commit details

Commits on Apr 28, 2023

  1. Add missing return types

    wouterj committed Apr 28, 2023
    Copy the full SHA
    2611ec9 View commit details
2 changes: 2 additions & 0 deletions AbstractUriElement.php
Original file line number Diff line number Diff line change
@@ -115,6 +115,8 @@ protected function canonicalizePath(string $path): string
*
* @param \DOMElement $node A \DOMElement instance
*
* @return void
*
* @throws \LogicException If given node is not an anchor
*/
abstract protected function setNode(\DOMElement $node);
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

6.3
---

* Add `$useHtml5Parser` argument to `Crawler`
* Add `CrawlerSelectorCount` test constraint
* Add argument `$normalizeWhitespace` to `Crawler::innerText()`
* Make `Crawler::innerText()` return the first non-empty text

6.0
---

65 changes: 57 additions & 8 deletions Crawler.php
Original file line number Diff line number Diff line change
@@ -58,16 +58,17 @@ class Crawler implements \Countable, \IteratorAggregate
*/
private bool $isHtml = true;

private HTML5 $html5Parser;

private ?HTML5 $html5Parser = null;

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

$this->add($node);
@@ -91,6 +92,8 @@ public function getBaseHref(): ?string

/**
* Removes all the nodes.
*
* @return void
*/
public function clear()
{
@@ -107,6 +110,8 @@ public function clear()
*
* @param \DOMNodeList|\DOMNode|\DOMNode[]|string|null $node A node
*
* @return void
*
* @throws \InvalidArgumentException when node is not the expected type
*/
public function add(\DOMNodeList|\DOMNode|array|string|null $node)
@@ -130,6 +135,8 @@ public function add(\DOMNodeList|\DOMNode|array|string|null $node)
* If the charset is not set via the content type, it is assumed to be UTF-8,
* or ISO-8859-1 as a fallback, which is the default charset defined by the
* HTTP 1.1 specification.
*
* @return void
*/
public function addContent(string $content, string $type = null)
{
@@ -170,6 +177,8 @@ public function addContent(string $content, string $type = null)
* internal errors via libxml_use_internal_errors(true)
* and then, get the errors via libxml_get_errors(). Be
* sure to clear errors with libxml_clear_errors() afterward.
*
* @return void
*/
public function addHtmlContent(string $content, string $charset = 'UTF-8')
{
@@ -204,6 +213,8 @@ public function addHtmlContent(string $content, string $charset = 'UTF-8')
* @param int $options Bitwise OR of the libxml option constants
* LIBXML_PARSEHUGE is dangerous, see
* http://symfony.com/blog/security-release-symfony-2-0-17-released
*
* @return void
*/
public function addXmlContent(string $content, string $charset = 'UTF-8', int $options = \LIBXML_NONET)
{
@@ -232,6 +243,8 @@ public function addXmlContent(string $content, string $charset = 'UTF-8', int $o
* Adds a \DOMDocument to the list of nodes.
*
* @param \DOMDocument $dom A \DOMDocument instance
*
* @return void
*/
public function addDocument(\DOMDocument $dom)
{
@@ -244,6 +257,8 @@ public function addDocument(\DOMDocument $dom)
* Adds a \DOMNodeList to the list of nodes.
*
* @param \DOMNodeList $nodes A \DOMNodeList instance
*
* @return void
*/
public function addNodeList(\DOMNodeList $nodes)
{
@@ -258,6 +273,8 @@ public function addNodeList(\DOMNodeList $nodes)
* Adds an array of \DOMNode instances to the list of nodes.
*
* @param \DOMNode[] $nodes An array of \DOMNode instances
*
* @return void
*/
public function addNodes(array $nodes)
{
@@ -270,6 +287,8 @@ public function addNodes(array $nodes)
* Adds a \DOMNode instance to the list of nodes.
*
* @param \DOMNode $node A \DOMNode instance
*
* @return void
*/
public function addNode(\DOMNode $node)
{
@@ -553,18 +572,34 @@ public function text(string $default = null, bool $normalizeWhitespace = true):
$text = $this->getNode(0)->nodeValue;

if ($normalizeWhitespace) {
return trim(preg_replace("/(?:[ \n\r\t\x0C]{2,}+|[\n\r\t\x0C])/", ' ', $text), " \n\r\t\x0C");
return $this->normalizeWhitespace($text);
}

return $text;
}

/**
* Returns only the inner text that is the direct descendent of the current node, excluding any child nodes.
*
* @param bool $normalizeWhitespace Whether whitespaces should be trimmed and normalized to single spaces
*/
public function innerText(): string
public function innerText(/* bool $normalizeWhitespace = true */): string
{
return $this->filterXPath('.//text()')->text();
$normalizeWhitespace = 1 <= \func_num_args() ? func_get_arg(0) : true;

foreach ($this->getNode(0)->childNodes as $childNode) {
if (\XML_TEXT_NODE !== $childNode->nodeType) {
continue;
}
if (!$normalizeWhitespace) {
return $childNode->nodeValue;
}
if ('' !== trim($childNode->nodeValue)) {
return $this->normalizeWhitespace($childNode->nodeValue);
}
}

return '';
}

/**
@@ -587,7 +622,7 @@ public function html(string $default = null): string
$node = $this->getNode(0);
$owner = $node->ownerDocument;

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

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

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

@@ -846,12 +881,17 @@ public function form(array $values = null, string $method = null): Form

/**
* Overloads a default namespace prefix to be used with XPath and CSS expressions.
*
* @return void
*/
public function setDefaultNamespacePrefix(string $prefix)
{
$this->defaultNamespacePrefix = $prefix;
}

/**
* @return void
*/
public function registerNamespace(string $prefix, string $namespace)
{
$this->namespaces[$prefix] = $namespace;
@@ -1176,6 +1216,10 @@ private function parseHtmlString(string $content, string $charset): \DOMDocument

private function canParseHtml5String(string $content): bool
{
if (!$this->html5Parser) {
return false;
}

if (false === ($pos = stripos($content, '<!doctype html>'))) {
return false;
}
@@ -1189,4 +1233,9 @@ private function isValidHtml5Heading(string $heading): bool
{
return 1 === preg_match('/^\x{FEFF}?\s*(<!--[^>]*?-->\s*)*$/u', $heading);
}

private function normalizeWhitespace(string $string): string
{
return trim(preg_replace("/(?:[ \n\r\t\x0C]{2,}+|[\n\r\t\x0C])/", ' ', $string), " \n\r\t\x0C");
}
}
12 changes: 11 additions & 1 deletion Field/ChoiceFormField.php
Original file line number Diff line number Diff line change
@@ -60,6 +60,8 @@ public function isDisabled(): bool

/**
* Sets the value of the field.
*
* @return void
*/
public function select(string|array|bool $value)
{
@@ -69,6 +71,8 @@ public function select(string|array|bool $value)
/**
* Ticks a checkbox.
*
* @return void
*
* @throws \LogicException When the type provided is not correct
*/
public function tick()
@@ -83,6 +87,8 @@ public function tick()
/**
* Unticks a checkbox.
*
* @return void
*
* @throws \LogicException When the type provided is not correct
*/
public function untick()
@@ -97,6 +103,8 @@ public function untick()
/**
* Sets the value of the field.
*
* @return void
*
* @throws \InvalidArgumentException When value type provided is not correct
*/
public function setValue(string|array|bool|null $value)
@@ -141,7 +149,7 @@ public function setValue(string|array|bool|null $value)
*
* @internal
*/
public function addChoice(\DOMElement $node)
public function addChoice(\DOMElement $node): void
{
if (!$this->multiple && 'radio' !== $this->type) {
throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
@@ -174,6 +182,8 @@ public function isMultiple(): bool
/**
* Initializes the form field.
*
* @return void
*
* @throws \LogicException When node type is incorrect
*/
protected function initialize()
10 changes: 10 additions & 0 deletions Field/FileFormField.php
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ class FileFormField extends FormField
*
* @param int $error The error code (one of UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, or UPLOAD_ERR_EXTENSION)
*
* @return void
*
* @throws \InvalidArgumentException When error code doesn't exist
*/
public function setErrorCode(int $error)
@@ -37,6 +39,8 @@ public function setErrorCode(int $error)

/**
* Sets the value of the field.
*
* @return void
*/
public function upload(?string $value)
{
@@ -45,6 +49,8 @@ public function upload(?string $value)

/**
* Sets the value of the field.
*
* @return void
*/
public function setValue(?string $value)
{
@@ -76,6 +82,8 @@ public function setValue(?string $value)

/**
* Sets path to the file as string for simulating HTTP request.
*
* @return void
*/
public function setFilePath(string $path)
{
@@ -85,6 +93,8 @@ public function setFilePath(string $path)
/**
* Initializes the form field.
*
* @return void
*
* @throws \LogicException When node type is incorrect
*/
protected function initialize()
4 changes: 4 additions & 0 deletions Field/FormField.php
Original file line number Diff line number Diff line change
@@ -92,6 +92,8 @@ public function getValue(): string|array|null

/**
* Sets the value of the field.
*
* @return void
*/
public function setValue(?string $value)
{
@@ -116,6 +118,8 @@ public function isDisabled(): bool

/**
* Initializes the form field.
*
* @return void
*/
abstract protected function initialize();
}
2 changes: 2 additions & 0 deletions Field/InputFormField.php
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@ class InputFormField extends FormField
/**
* Initializes the form field.
*
* @return void
*
* @throws \LogicException When node type is incorrect
*/
protected function initialize()
2 changes: 2 additions & 0 deletions Field/TextareaFormField.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ class TextareaFormField extends FormField
/**
* Initializes the form field.
*
* @return void
*
* @throws \LogicException When node type is incorrect
*/
protected function initialize()
Loading