Skip to content
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
64 changes: 0 additions & 64 deletions php-transformer/src/HtmlToBlocks/Diagnostics/FallbackEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,42 +708,6 @@ private function topClassificationSignals(array $signals): array
), static fn (mixed $value): bool => array() !== $value);
}

private function runtimeIslandSelector(DOMElement $element): string
{
$id = trim($this->attr($element, 'id'));
if ( '' !== $id ) {
return '#' . $id;
}

foreach ( preg_split('/\s+/', trim($this->attr($element, 'class'))) ?: array() as $class ) {
if ( '' !== $class ) {
return '.' . $class;
}
}

return $this->elementSelector($element);
}

/**
* @param array<int, array<string, mixed>> $rows
* @return array<int, array<string, mixed>>
*/
private function dedupeArrayRows(array $rows): array
{
$seen = array();
$deduped = array();
foreach ( $rows as $row ) {
$key = json_encode($row, JSON_UNESCAPED_SLASHES);
if ( ! is_string($key) || isset($seen[$key]) ) {
continue;
}
$seen[$key] = true;
$deduped[] = $row;
}

return $deduped;
}

private function templateRequiresRuntimePreservation(DOMElement $element): bool
{
foreach ( $this->htmlAttributes($element) as $name => $value ) {
Expand Down Expand Up @@ -897,32 +861,4 @@ private function safeSvgAttributes(DOMElement $element): array
return $attributes;
}

/**
* @return array<int, array<string, string>>
*/
private function eventMetadata(DOMElement $element): array
{
$events = array();
foreach ( $this->htmlAttributes($element) as $name => $value ) {
if ( preg_match('/^on([a-z]+)$/i', $name, $matches) ) {
$events[] = array(
'type' => strtolower($matches[1]),
'attribute' => strtolower($name),
);
}
if ( preg_match('/^data-(?:action|on|event)$/i', $name) && '' !== trim($value) ) {
$events[] = array(
'type' => 'declared',
'attribute' => $name,
);
}
}

return $events;
}

private function isSafeSvgContent(string $content): bool
{
return '' !== trim($content) && preg_match('/<svg(?:\s|>)/i', $content) && ! preg_match('/<\s*script\b|\son[a-z]+\s*=|javascript\s*:/i', $content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,6 @@ private function landmarkKindForElement(DOMElement $element): string
};
}

/**
* @param array<int, string> $tagNames
*/
private function hasAncestorTag(DOMElement $element, array $tagNames): bool
{
for ( $node = $element->parentNode; $node instanceof DOMElement && 'body' !== strtolower($node->tagName); $node = $node->parentNode ) {
if ( in_array(strtolower($node->tagName), $tagNames, true) ) {
return true;
}
}

return false;
}

/**
* @param array<int, array<string, mixed>> $blocks
* @param array<int, array<string, mixed>> $sourceProvenance
Expand Down Expand Up @@ -367,23 +353,6 @@ private function isSourceMenuToggleControl(DOMElement $element): bool
return (bool) preg_match('/(?:^|[^a-z0-9])(?:hamburger|menu|toggle)(?:[^a-z0-9]|$)/', strtolower($this->attr($element, 'class') . ' ' . $this->attr($element, 'aria-label')));
}

private function hasSourceNavigationSignal(DOMElement $element): bool
{
if ( 'navigation' === strtolower($this->attr($element, 'role')) ) {
return true;
}

foreach ( array( 'class', 'id' ) as $attribute ) {
foreach ( preg_split('/[^a-z0-9]+/', strtolower($this->attr($element, $attribute))) ?: array() as $token ) {
if ( in_array($token, array( 'nav', 'navbar', 'navigation', 'menu', 'links' ), true) ) {
return true;
}
}
}

return false;
}

/**
* @param array<int, string> $tagNames
*/
Expand Down Expand Up @@ -840,18 +809,4 @@ private function navigationItemsSignature(array $items): string
return implode('|', $parts);
}

/**
* Sanitize a navigation URL, dropping control characters and javascript:
* schemes. Copied from HtmlTransformer (which retains it for non-parity
* callers) so the parity reporter has no dependency on transformer state.
*/
private function safeNavigationUrl(string $url): string
{
$url = trim($url);
if ( '' === $url || preg_match('/[\x00-\x1f\x7f]|javascript\s*:/i', $url) ) {
return '';
}

return $url;
}
}
108 changes: 0 additions & 108 deletions php-transformer/src/HtmlToBlocks/HtmlTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,36 +421,6 @@ private function deduplicateNavigationBlocks(array $blocks): array
return $this->deduplicateNavigationBlocksRecursive($blocks, $seen);
}

/**
* @param array<int, string> $tagNames
*/
private function hasAncestorTag(DOMElement $element, array $tagNames): bool
{
for ( $node = $element->parentNode; $node instanceof DOMElement && 'body' !== strtolower($node->tagName); $node = $node->parentNode ) {
if ( in_array(strtolower($node->tagName), $tagNames, true) ) {
return true;
}
}

return false;
}
private function hasSourceNavigationSignal(DOMElement $element): bool
{
if ( 'navigation' === strtolower($this->attr($element, 'role')) ) {
return true;
}

foreach ( array( 'class', 'id' ) as $attribute ) {
foreach ( preg_split('/[^a-z0-9]+/', strtolower($this->attr($element, $attribute))) ?: array() as $token ) {
if ( in_array($token, array( 'nav', 'navbar', 'navigation', 'menu', 'links' ), true) ) {
return true;
}
}
}

return false;
}

/**
* @param array<int, array<string, mixed>> $blocks
* @param array<string, bool> $seen
Expand Down Expand Up @@ -3031,22 +3001,6 @@ private function recordRuntimeIsland(DOMElement $element, string $kind, string $
$this->fallbackEmitter->recordRuntimeIsland($element, $kind, $reason, $runtimeRequirement, $metadata, $this->runtimeIslands);
}

private function runtimeIslandSelector(DOMElement $element): string
{
$id = trim($this->attr($element, 'id'));
if ( '' !== $id ) {
return '#' . $id;
}

foreach ( preg_split('/\s+/', trim($this->attr($element, 'class'))) ?: array() as $class ) {
if ( '' !== $class ) {
return '.' . $class;
}
}

return $this->elementSelector($element);
}

/**
* @return array<int, array<string, mixed>>
*/
Expand Down Expand Up @@ -3092,26 +3046,6 @@ private function generatedBlockNamespaceFromOptions(array $options): string
return '' !== $namespace ? $namespace : 'custom';
}

/**
* @param array<int, array<string, mixed>> $rows
* @return array<int, array<string, mixed>>
*/
private function dedupeArrayRows(array $rows): array
{
$seen = array();
$deduped = array();
foreach ( $rows as $row ) {
$key = json_encode($row, JSON_UNESCAPED_SLASHES);
if ( ! is_string($key) || isset($seen[$key]) ) {
continue;
}
$seen[$key] = true;
$deduped[] = $row;
}

return $deduped;
}

/**
* @param array<string, mixed> $options
* @return array<string, bool>
Expand Down Expand Up @@ -4153,16 +4087,6 @@ private function hasNavigationContainerSignal(DOMElement $element): bool
return (bool) preg_match('/(?:^|[\s_-])(?:nav|navbar|navigation|menu|links)(?:$|[\s_-])/', $name);
}

private function safeNavigationUrl(string $url): string
{
$url = trim($url);
if ( '' === $url || preg_match('/[\x00-\x1f\x7f]|javascript\s*:/i', $url) ) {
return '';
}

return $url;
}

private function hasDirectChildElement(DOMElement $element, string $tagName): bool
{
foreach ( $element->childNodes as $child ) {
Expand Down Expand Up @@ -4684,11 +4608,6 @@ private function safeResolvedAssetImageUrl(string $url): string
return $this->safeImageUrl($url);
}

private function isSafeSvgContent(string $content): bool
{
return '' !== trim($content) && preg_match('/<svg(?:\s|>)/i', $content) && ! preg_match('/<\s*script\b|\son[a-z]+\s*=|javascript\s*:/i', $content);
}

/**
* @return array<string, string>
*/
Expand Down Expand Up @@ -4789,31 +4708,4 @@ private function sanitizedSyntaxHtml(DOMElement $element): string
return $html;
}

/**
* @param array<string, string> $attrs
*/
/**
* @return array<int, array<string, string>>
*/
private function eventMetadata(DOMElement $element): array
{
$events = array();
foreach ( $this->htmlAttributes($element) as $name => $value ) {
if ( preg_match('/^on([a-z]+)$/i', $name, $matches) ) {
$events[] = array(
'type' => strtolower($matches[1]),
'attribute' => strtolower($name),
);
}
if ( preg_match('/^data-(?:action|on|event)$/i', $name) && '' !== trim($value) ) {
$events[] = array(
'type' => 'declared',
'attribute' => $name,
);
}
}

return $events;
}

}
Loading
Loading