Skip to content
Snippets Groups Projects
Commit 37d33f5e authored by Teun van Veggel's avatar Teun van Veggel
Browse files

Issue #3491478 by somatick: EmbeddedContentButton regex produces a warning

parent 120da669
No related branches found
No related tags found
No related merge requests found
Pipeline #403150 failed
......@@ -7,6 +7,7 @@
"require": {
"drupal/core": "^9 || ^10 || ^11",
"symfony/css-selector": "^6 || ^7",
"symfony/dom-crawler": "^6 || ^7"
"symfony/dom-crawler": "^6 || ^7",
"ext-libxml": "*"
}
}
......@@ -93,8 +93,6 @@ final class EmbeddedContentButton extends ConfigEntityBase implements EmbeddedCo
/**
* {@inheritdoc}
*
* @todo Handle incorrect expressions better.
*/
public function meetsCondition(string $plugin_id): bool {
$patterns = $this->getConditions();
......@@ -104,7 +102,7 @@ final class EmbeddedContentButton extends ConfigEntityBase implements EmbeddedCo
foreach ($patterns as $pattern) {
// Allow for regex patterns.
try {
if ((bool) preg_match($pattern, $plugin_id)) {
if (@preg_match($pattern, $plugin_id)) {
return TRUE;
}
}
......@@ -112,14 +110,11 @@ final class EmbeddedContentButton extends ConfigEntityBase implements EmbeddedCo
// Ignore invalid patterns.
}
$pattern = '/^' . str_replace('*', '(.*)', $pattern) . '$/';
try {
if ((bool) preg_match($pattern, $plugin_id)) {
return TRUE;
}
}
catch (\Throwable $e) {
// Ignore invalid patterns.
if (@preg_match($pattern, $plugin_id)) {
return TRUE;
}
}
return FALSE;
......
......@@ -100,10 +100,16 @@ class EmbeddedContent extends FilterBase implements ContainerFactoryPluginInterf
]
))->render();
}
$fragment = $document->createDocumentFragment();
$html = Html::normalize($render);
$fragment->appendXML($html);
$node->parentNode->replaceChild($fragment, $node);
// Replace the node with the rendered content.
// @see https://www.drupal.org/project/embedded_content/issues/3496686
libxml_use_internal_errors(TRUE);
$new = Html::load($render);
libxml_clear_errors();
$xpath = new \DOMXPath($new);
$new_node = $document->importNode($xpath->query('//body')->item(0), TRUE);
libxml_use_internal_errors(FALSE);
$node->parentNode->replaceChild($new_node, $node);
}
$result = new FilterProcessResult(Html::serialize($document));
$result->addCacheableDependency($bubbleable);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment