🐛 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:
+10
-1
@@ -125,7 +125,15 @@ var
|
||||
begin
|
||||
element := AssureElement(AParent, AName);
|
||||
if assigned(element.FirstChild) then
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user