Dom\HTMLDocument: Impossible to add text node on document level
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Empieza reproduciendo el fragmento de PHP con Dom\HTMLDocument::createFromString, LIBXML_HTML_NOIMPLIED y CharacterData::replaceWith(). Traza cómo replaceWith(), insertAdjacentHTML() y appendChild() gestionan los nodos de texto a nivel de documento y, después, compara los puntos de entrada de Lexbor conformes y no conformes con la especificación mencionados en el issue. Se considera terminado cuando se haya llegado a una decisión clara y se haya implementado o documentado un comportamiento coherente para los documentos NOIMPLIED, con pruebas para el caso mostrado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
The following code...
$doc = \Dom\HTMLDocument::createFromString('Hello <b>world</b>!',LIBXML_HTML_NOIMPLIED);
$greeting = $doc->firstChild;
echo get_class($greeting)."<br />";
$new_greeting = $doc->createTextNode('Welcome');
$greeting->replaceWith($new_greeting);
echo htmlentities($doc->saveHtml());
results in this error:
DOMException: Cannot insert text as a child of a document in Dom\CharacterData->replaceWith()
This is different behavior from the old DOM classes which allowed this. I understand, this spec-compliance is supposed to be a feature. If I understand correctly, the new Lexbor-based parser offers validity checks for some methods and not for others:
https://lexbor.com/modules/dom/
E.g. lxb_dom_node_insert_before_spec vs lxb_dom_node_insert_before etc.
I'm unaware of the current PHP implementation but I assume it is using the _spec versions throughout without any option to turn it off.
I think this is problematic. The NOIMPLIED option is very useful indeed if you want to handle document fragments etc. without unnecessary wrapper tags.
The above code leads to the peculiar situation that you can indeed create a Document with textNodes on the document level, but if you just want to replace that textNode with a different textNode it won't work. This complicates things a lot unnecessarily. Other methods like insertAdjacentHTML, appendChild etc are equally stubborn.
There are different solutions for this: IMHO the easiest one would be to use the non-spec versions of these functions if NOIMPLIED was specified. NOIMPLIED explicitly allows a non-spec document to be imported. Any manipulation should also be allowed then.
Another alternative would be to create a new general flag LIBXML_HTML_RELAX_SPEC.
A third alternative would be to specifically add option flags to the individual methods to allow this for a single call.
I'm unsure what's really the best solution but at the moment, porting over existing code is unnecessarily difficult due to this restriction and I really think this feature would make a lot of sense anyway. Thanks for considering.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.2k
- Merge medio
- 2 d 17 h
- PR fusionados (30 d)
- 115
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de php/php-src
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
Bug Status: Needs Triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Flaky hrtime.phpt test AbiertoBug Category: Tests Status: Verified
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Bug SAPI: fpm Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Todos los issues de php/php-src
Issues similares
-
os:linux
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
mpv-player/mpv#18510 · 2 comentarios ·
-
internal.h中,漏掉了1个定义。 Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Broadcast Documentation Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
kovidgoyal/kitty#10516 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100