Dom\HTMLDocument: Impossible to add text node on document level
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
Beginne damit, das PHP-Snippet mit Dom\HTMLDocument::createFromString, LIBXML_HTML_NOIMPLIED und CharacterData::replaceWith() nachzustellen. Verfolge, wie replaceWith(), insertAdjacentHTML() und appendChild() mit Textknoten auf Dokumentebene umgehen, und vergleiche anschließend die im Issue erwähnten spezifikationskonformen und nicht spezifikationskonformen Lexbor-Einstiegspunkte. Erledigt ist die Aufgabe, wenn eine klare Entscheidung erreicht und ein konsistentes Verhalten für NOIMPLIED-Dokumente implementiert oder dokumentiert wurde, mit Tests für den gezeigten Fall.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- C
- Sterne
- 40.4k
- Forks
- 8.2k
- Ø Merge
- 2 T. 3 Std.
- Gemergte PRs (30 T.)
- 151
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus php/php-src
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
php/php-src#24121 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Variant analysis: 1 unfixed sibling safety gap in php-srcEvtl. vergeben @kamil-tekiela hat das vor 6 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
php/php-src#23958 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
sapi_lsapi_ub_write does not return bytes written in lsapi modeEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. OffenBug Status: Needs Triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
Maintainer antworten meist innerhalb von 1 Tag
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Flaky hrtime.phpt testEvtl. vergeben @veksa hat das vor 62 Tagen übernommen. OffenBug Category: Tests Status: Verified
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
libsdl-org/SDL#16444 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug Component component: net
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
RT-Thread/rt-thread#11852 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
MiSTer-devel/ao486_MiSTer#243 ·
-
Dropped last row with parallel scan of attached SQLite tables if the rowid range is a multiple of 122,880Evtl. vergeben @staticlibs hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
duckdb/duckdb-sqlite#240 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
siderolabs/pkgs#1710 ·
Maintainer antworten meist innerhalb von 1 Tag