Add test script for malformed lists fix validation
Demonstrates proposed regex replacement pattern without applying changes. For validation before mass update. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
91
Shared/Infrastructure/Scripts/test-fix-lists.php
Normal file
91
Shared/Infrastructure/Scripts/test-fix-lists.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Script de PRUEBA - Muestra corrección propuesta sin aplicarla
|
||||||
|
*
|
||||||
|
* IMPORTANTE: Este script SOLO MUESTRA, no modifica nada.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$conn = new mysqli("localhost", "preciosunitarios_seo", "ACl%EEFd=V-Yvb??", "preciosunitarios_seo");
|
||||||
|
$conn->set_charset("utf8mb4");
|
||||||
|
|
||||||
|
echo "========================================\n";
|
||||||
|
echo "ANÁLISIS DE CORRECCIÓN PROPUESTA\n";
|
||||||
|
echo "========================================\n\n";
|
||||||
|
|
||||||
|
// Patrón que encuentra: </li></ul><li>TEXTO</li><ul>
|
||||||
|
// Este patrón captura:
|
||||||
|
// - $1: </li> inicial (con espacios)
|
||||||
|
// - $2: espacios entre </ul> y <li>
|
||||||
|
// - $3: contenido del <li> (ej: <strong>Texto</strong>)
|
||||||
|
// - $4: espacios entre </li> y <ul>
|
||||||
|
|
||||||
|
$pattern = '#(</li>\s*)</ul>(\s*)<li>(.*?)</li>(\s*)<ul>#is';
|
||||||
|
$replacement = '$1<li>$3$4<ul>';
|
||||||
|
|
||||||
|
echo "PATRÓN A BUSCAR:\n";
|
||||||
|
echo " </li>\\s*</ul>\\s*<li>CONTENIDO</li>\\s*<ul>\n\n";
|
||||||
|
|
||||||
|
echo "REEMPLAZO:\n";
|
||||||
|
echo " </li><li>CONTENIDO<ul>\n\n";
|
||||||
|
|
||||||
|
// Obtener HTML del post ID 3
|
||||||
|
$result = $conn->query("SELECT id, page, html FROM datos_seo_pagina WHERE id = 3");
|
||||||
|
$row = $result->fetch_assoc();
|
||||||
|
$html = $row["html"];
|
||||||
|
$page = $row["page"];
|
||||||
|
|
||||||
|
echo "PROBANDO CON POST ID 3:\n";
|
||||||
|
echo "URL: $page\n";
|
||||||
|
echo "────────────────────────────\n\n";
|
||||||
|
|
||||||
|
// Encontrar todas las ocurrencias
|
||||||
|
preg_match_all($pattern, $html, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
|
||||||
|
|
||||||
|
echo "Ocurrencias encontradas: " . count($matches) . "\n\n";
|
||||||
|
|
||||||
|
// Mostrar cada ocurrencia y su corrección propuesta
|
||||||
|
foreach (array_slice($matches, 0, 3) as $idx => $match) {
|
||||||
|
$full_match = $match[0][0];
|
||||||
|
$position = $match[0][1];
|
||||||
|
|
||||||
|
echo "[$idx] Posición: $position\n";
|
||||||
|
echo "ANTES:\n";
|
||||||
|
echo htmlspecialchars($full_match) . "\n\n";
|
||||||
|
|
||||||
|
$fixed = preg_replace($pattern, $replacement, $full_match);
|
||||||
|
echo "DESPUÉS:\n";
|
||||||
|
echo htmlspecialchars($fixed) . "\n";
|
||||||
|
echo "────────────────────────────\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aplicar corrección en memoria y contar diferencia
|
||||||
|
$html_fixed = preg_replace($pattern, $replacement, $html);
|
||||||
|
|
||||||
|
$before = preg_match_all($pattern, $html);
|
||||||
|
$after = preg_match_all($pattern, $html_fixed);
|
||||||
|
|
||||||
|
echo "========================================\n";
|
||||||
|
echo "RESUMEN DE CORRECCIÓN (sin aplicar):\n";
|
||||||
|
echo "========================================\n";
|
||||||
|
echo "Ocurrencias ANTES: $before\n";
|
||||||
|
echo "Ocurrencias DESPUÉS: $after\n";
|
||||||
|
echo "Reducción: " . ($before - $after) . "\n\n";
|
||||||
|
|
||||||
|
// Verificar que la estructura es válida después de la corrección
|
||||||
|
$ul_count_before = substr_count($html, '<ul');
|
||||||
|
$ul_count_after = substr_count($html_fixed, '<ul');
|
||||||
|
echo "Tags <ul> antes: $ul_count_before\n";
|
||||||
|
echo "Tags <ul> después: $ul_count_after\n";
|
||||||
|
|
||||||
|
$li_count_before = substr_count($html, '<li');
|
||||||
|
$li_count_after = substr_count($html_fixed, '<li');
|
||||||
|
echo "Tags <li> antes: $li_count_before\n";
|
||||||
|
echo "Tags <li> después: $li_count_after\n";
|
||||||
|
|
||||||
|
echo "\n========================================\n";
|
||||||
|
echo "NOTA: Este patrón elimina el </ul> prematuro\n";
|
||||||
|
echo "pero NO agrega el </li> faltante al final.\n";
|
||||||
|
echo "Se necesita un segundo paso para balancear.\n";
|
||||||
|
echo "========================================\n";
|
||||||
|
|
||||||
|
$conn->close();
|
||||||
Reference in New Issue
Block a user