Browse Source

Minor bugfixes

wrapper-classes
Dustin Wilson 3 years ago
parent
commit
c533f8e63f
  1. 9
      composer.lock
  2. 14
      lib/Document.php
  3. 30
      lib/Serializer.php
  4. 14
      vendor-bin/phpunit/composer.lock

9
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6ed06e9556bdcc4bbbb5f3f23958e33d",
"content-hash": "80f59b5505ffc9b8d7fd2a408538d861",
"packages": [
{
"name": "mensbeam/framework",
@ -59,11 +59,11 @@
},
{
"name": "mensbeam/html-parser",
"version": "dev-master",
"version": "dev-pretty-print",
"source": {
"type": "git",
"url": "mensbeam-gitea:MensBeam/HTML-Parser.git",
"reference": "c5a3d635d542de6acfb704557341d37944a2e688"
"reference": "b145e1ebc9c94e3e0a8267345b21067c5b0dc110"
},
"require": {
"ext-dom": "*",
@ -77,7 +77,6 @@
"suggest": {
"ext-ctype": "Improved performance"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
@ -130,7 +129,7 @@
"parsing",
"whatwg"
],
"time": "2021-11-08T18:34:05+00:00"
"time": "2021-11-16T22:47:08+00:00"
},
{
"name": "mensbeam/intl",

14
lib/Document.php

@ -443,6 +443,11 @@ class Document extends Node {
switch ($key) {
case 'indentStep':
if (!is_int($value)) {
$type = gettype($value);
if ($type === 'object') {
$type = get_class($value);
}
trigger_error("Value for serializer configuration option \"$key\" must be an integer; $type given", \E_USER_WARNING);
continue 2;
}
break;
@ -451,10 +456,17 @@ class Document extends Node {
case 'serializeBooleanAttributeValues':
case 'serializeForeignVoidEndTags':
if (!is_bool($value)) {
$type = gettype($value);
if ($type === 'object') {
$type = get_class($value);
}
trigger_error("Value for serializer configuration option \"$key\" must be an integer; $type given", \E_USER_WARNING);
continue 2;
}
break;
default: continue 2;
default:
trigger_error("\"$key\" is an invalid serializer configuration option", \E_USER_WARNING);
continue 2;
}
$parserConfig->$key = $value;

30
lib/Serializer.php

@ -45,28 +45,16 @@ class Serializer extends ParserSerializer {
return false;
}
protected static function treatAsBlock(\DOMNode $node): bool {
// NOTE: This method is used only when pretty printing. Implementors of userland
// PHP DOM solutions with template contents will need to extend this method to
// check for any templates and look within their content fragments for "block"
// content.
if ($node instanceof \DOMDocument || $node instanceof \DOMDocumentFragment) {
return true;
}
protected static function treatAsBlockWithTemplates(\DOMNode $node): bool {
$templates = $xpath->query('.//template[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"][not(ancestor::iframe[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::listing[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::noembed[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::noframes[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::noscript[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::plaintext[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::pre[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::style[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::script[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::textarea[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::title[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::xmp[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"])]', $node);
$xpath = new \DOMXPath($node->ownerDocument);
$result = ($xpath->evaluate(self::BLOCK_QUERY, $node) > 0);
foreach ($templates as $t) {
$content = Reflection::getProtectedProperty($t->ownerDocument->getWrapperNode($t)->content, 'innerNode');
if (!$result) {
$templates = $xpath->query('.//template[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"][not(ancestor::iframe[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::listing[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::noembed[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::noframes[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::noscript[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::plaintext[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::pre[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::style[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::script[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::textarea[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::title[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"] or ancestor::xmp[namespace-uri()="" or namespace-uri()="http://www.w3.org/1999/xhtml"])]');
foreach ($templates as $t) {
$content = Reflection::getProtectedProperty($t->ownerDocument->getWrapperNode($t)->content, 'innerNode');
// This circumvents a PHP XPath bug where it will silently fail to query
// nodes within fragments.
$clone = $content->cloneNode(true);
$span = $content->ownerDocument->createElement('span');
// This circumvents a PHP XPath bug where it will silently fail to query
// nodes within fragments.
$clone = $content->cloneNode(true);
$span = $content->ownerDocument->createElement('span');
$span->appendChild($clone);
if ($xpath->evaluate(self::BLOCK_QUERY, $span) > 0) {
@ -75,7 +63,7 @@ class Serializer extends ParserSerializer {
}
}
return $result;
return false;
}
protected static function treatForeignRootAsBlock(\DOMNode $node): bool {

14
vendor-bin/phpunit/composer.lock

@ -1377,16 +1377,16 @@
},
{
"name": "sebastian/exporter",
"version": "4.0.3",
"version": "4.0.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65"
"reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d89cc98761b8cb5a1a235a6b703ae50d34080e65",
"reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/65e8b7db476c5dd267e65eea9cab77584d3cfff9",
"reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9",
"shasum": ""
},
"require": {
@ -1435,14 +1435,14 @@
}
],
"description": "Provides the functionality to export PHP variables for visualization",
"homepage": "http://www.github.com/sebastianbergmann/exporter",
"homepage": "https://www.github.com/sebastianbergmann/exporter",
"keywords": [
"export",
"exporter"
],
"support": {
"issues": "https://github.com/sebastianbergmann/exporter/issues",
"source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3"
"source": "https://github.com/sebastianbergmann/exporter/tree/4.0.4"
},
"funding": [
{
@ -1450,7 +1450,7 @@
"type": "github"
}
],
"time": "2020-09-28T05:24:23+00:00"
"time": "2021-11-11T14:18:36+00:00"
},
{
"name": "sebastian/global-state",

Loading…
Cancel
Save