🐛 Check node type before treating XML children as text

Reading or updating a value whose first child was a comment or CDATA
node crashed with a failed class cast.
This commit is contained in:
2026-11-15 22:06:50 +01:00
parent 39045b76c1
commit e527149f63
+11 -2
View File
@@ -125,7 +125,15 @@ var
begin
element := AssureElement(AParent, AName);
if assigned(element.FirstChild) then
TDOMText(element.FirstChild).NodeValue := AValue
begin
if element.FirstChild.NodeType = TEXT_NODE then
TDOMText(element.FirstChild).NodeValue := AValue
else
begin
element.RemoveChild(element.FirstChild).Free;
element.AppendChild(AParent.OwnerDocument.CreateTextNode(AValue));
end;
end
else
element.AppendChild(AParent.OwnerDocument.CreateTextNode(AValue));
end;
@@ -135,7 +143,8 @@ var
element: TDOMElement;
begin
element := FindChild(AParent, AName);
if assigned(element) and assigned(element.FirstChild) then
if assigned(element) and assigned(element.FirstChild)
and (element.FirstChild.NodeType = TEXT_NODE) then
Result := TDOMText(element.FirstChild).Data
else
Result := ADefault;