mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-16 23:21:57 +02:00
XML writer: split CDATA sections at the ']]>' sequence.
git-svn-id: trunk@14186 -
This commit is contained in:
parent
60a9ef963d
commit
5c60f0e9e2
@ -316,6 +316,7 @@ end;
|
||||
const
|
||||
AttrSpecialChars = ['<', '"', '&', #9, #10, #13];
|
||||
TextSpecialChars = ['<', '>', '&'];
|
||||
CDSectSpecialChars = [']'];
|
||||
|
||||
procedure TXMLWriter.ConvWrite(const s: WideString; const SpecialChars: TSetOfChar;
|
||||
const SpecialCharCallback: TSpecialCharCallback);
|
||||
@ -372,6 +373,19 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure CDSectSpecialCharCallback(Sender: TXMLWriter; const s: DOMString;
|
||||
var idx: Integer);
|
||||
begin
|
||||
if (idx <= Length(s)-2) and (s[idx+1] = ']') and (s[idx+2] = '>') then
|
||||
begin
|
||||
Sender.wrtStr(']]]]><![CDATA[>');
|
||||
Inc(idx, 2);
|
||||
// TODO: emit warning 'cdata-section-splitted'
|
||||
end
|
||||
else
|
||||
Sender.wrtChr(s[idx]);
|
||||
end;
|
||||
|
||||
procedure TXMLWriter.WriteNode(node: TDOMNode);
|
||||
begin
|
||||
case node.NodeType of
|
||||
@ -598,7 +612,7 @@ begin
|
||||
else
|
||||
begin
|
||||
wrtChars('<![CDATA[', 9);
|
||||
wrtStr(TDOMCharacterData(node).Data);
|
||||
ConvWrite(TDOMCharacterData(node).Data, CDSectSpecialChars, @CDSectSpecialCharCallback);
|
||||
wrtChars(']]>', 3);
|
||||
end;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user