From 8f49adf3c8876c6aa0c4f367ed1808efcb49f68f Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 11 Jun 2011 11:54:01 +0000 Subject: [PATCH] * Patch from Ido Kanner to add HTMLEncode and HTMLDecode git-svn-id: trunk@17718 - --- packages/fcl-xml/src/htmlelements.pp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/fcl-xml/src/htmlelements.pp b/packages/fcl-xml/src/htmlelements.pp index fe579dda1b..5f0e5a25f3 100644 --- a/packages/fcl-xml/src/htmlelements.pp +++ b/packages/fcl-xml/src/htmlelements.pp @@ -128,8 +128,30 @@ type procedure WriteToStream (const aStream : TStream); override; end; +function EscapeHTML(const s : String) : String; +function UnescapeHTML(const s : String) : String; + implementation +function EscapeHTML ( const S : String ) : String; +begin + Result := StringReplace(s, '&', '&', [rfReplaceAll]); + Result := StringReplace(Result, '<', '<', [rfReplaceAll]); + Result := StringReplace(Result, '>', '>', [rfReplaceAll]); + Result := StringReplace(Result, '"', '"', [rfReplaceAll]); + Result := StringReplace(Result, #39, ''', [rfReplaceAll]); // ' - ' does not work on ie :( +end; + +function UnescapeHTML ( const S : String ) : String; +begin + Result := StringReplace(s, '<', '<', [rfReplaceAll]); + Result := StringReplace(Result, '>', '>', [rfReplaceAll]); + Result := StringReplace(Result, '"', '"', [rfReplaceAll]); + Result := StringReplace(Result, ''', #39, [rfReplaceAll]); // ' + Result := StringReplace(Result, ''', #39, [rfReplaceAll]); // ' + Result := StringReplace(Result, '&', '&', [rfReplaceAll]); +end; + { THtmlCustomElement } @@ -201,8 +223,7 @@ end; function THtmlCustomElement.EscapeString(s: string): string; begin - result := s; - //TODO: Needs to convert all the special signs to their html names ("<" has to be "<" etc.) + result := EscapeHTML(s); end; constructor THtmlCustomElement.create(AOwner: TDOMDocument);