Hello,
Does fpWeb have any method/function that escape and un-escape html and URI elements ?
Thanks,
Ido
LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il

Mailing lists / fpc-pascal / 2011-05
13 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hello,
Does fpWeb have any method/function that escape and un-escape html and URI elements ?
Thanks,
Ido
LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il
ik wroteHello, Does fpWeb have any method/function that escape and un-escape html and URI elements ?
Yes.
in fphttpclient:
Function EncodeURLElement(S : String) : String;
Function DecodeURLElement(Const S : String) : String;We should maybe move them to URIParser or maybe even strutils.
Michael.
I can not find any HTML encode and decode, I'll make one and open a bug with the patches.
Where do you think it will be best to place it (I mean the unit) ?
Michael.
Thanks,
Ido
_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Does fpWeb have any method/function that escape and un-escape html and URI elements ? Ido…
There are
Function HTTPDecode(const AStr: String): String;
Function HTTPEncode(const AStr: String): String;in unit httpdefs.pp of fcl-web.
AB
On Tue, May 24, 2011 at 00:23, Michael Van Canneyt I can not find any HTML encode and…
I've created a patch with the Escape and unEscape functions, and place it here: http://bugs.freepascal.org/view.php?id=19407
Hello FPC-Pascal,
Tuesday, May 24, 2011, 10:09:03 AM, you wrote:
i> I've created a patch with the Escape and unEscape functions, and place it i> here: http://bugs.freepascal.org/view.php?id=19407
Un/escapeHTML parsing must be in one go, specially the "&" one. Test against:
"<"
Right unescape "<", your code "<".
I'm not sure what you mean here.
If you have already html entities you should not escape them. If you do not have html entities you should escape them.
The Escaping and unescaping works well, I already tested them before I sent them.
Ido
You should not unescape recursively.
Input to EscapeHTML: '<' Output: '&lt;' : Correct UnescapeHTML: input '&lt;' Output '<' Wrong. This is because you replace '&' with '&' resulting in '<' which is translated to '< ' in the next line.
Ludo
So you suggest to place the & translation last.
I've created a patch with the Escape and unEscape functions, and place it here:…
This is a very minimalistic implementation covering only partial ascii character escaping. To cover ASCII only in unescapeHTML you should also add ' ' which corresponds with the space character ' '. Also the format &#entity_number; is missing ('<' or '<' equals '<')
To support iso-8859-1 which is default in most browsers you'll need a lot more. See f.e. http://www.w3schools.com/tags/ref_entities.asp
Ludo
I'm not sure what you mean here. If you have already html entities you should not escape…
Hello FPC-Pascal,
you wrote> "&lt;"
i> I'm not sure what you mean here.
That's an already escaped html. Let it be a mini htmlpage:
<html><title>-&lt;-</title></html>
i> If you have already html entities you should not escape them. If you do not i> have html entities you should escape them.
i> The Escaping and unescaping works well, I already tested them before I sent i> them.
The right content of <title> tag is "-<-" when unescaped but the code unescapehtml produce "-<-". Explanation step by step:
1) The code looks for all '&'
2) When found replace it by '&'
3) <title> content is now "-<-"
4) Now the code looks for '<'
5) When found replace it by '<'
6) Now title content is "-<-"
----------
Result := StringReplace(s, '&', '&', [rfReplaceAll]);
Result := StringReplace(Result, '<', '<', [rfReplaceAll]);
----------I hope my explanations are now understandable.
So you suggest to place the & translation last.
So you suggest to place the & translation last.
That would be a solution for this problem. My previous comments on the "minimalistic" approach of the implementation suggest a different approach: scan the source string once and replace html entities as you find them (with a look up table for example). This would scale much better when implementing iso-8859-1 or '&#entity-number;' unescaping .
Ludo
For every html entity you need a dictionary, and that's makes your program with more fat.
converting number entity can be done, but you need to know what is the code page you wish to convert from/to.
Ludo
Ido