Encode more unsafe characters in urls

This commit is contained in:
Ansgar Becker
2012-05-01 12:10:17 +00:00
parent 62c0396165
commit 30474de294
2 changed files with 15 additions and 6 deletions

View File

@@ -143,7 +143,7 @@ type
function decrypt(str: String): String;
function htmlentities(str: String): String;
function BestTableName(Data: TDBQuery): String;
function urlencode(url: String): String;
function EncodeURL(const Src: String): String;
procedure StreamWrite(S: TStream; Text: String = '');
function _GetFileSize(Filename: String): Int64;
function MakeInt( Str: String ) : Int64;
@@ -406,14 +406,23 @@ end;
{***
Encode spaces (and more to come) in URLs
Encode critical characters in URL segments
@param string URL to encode
@return string
}
function urlencode(url: String): String;
function EncodeURL(const Src: String): String;
var
i: Integer;
const
SafeChars = ['A'..'Z','a'..'z','*','@','.','_','-','0'..'9','$','!','''','(',')'];
begin
result := stringreplace(url, ' ', '+', [rfReplaceAll]);
Result := '';
for i:=1 to Length(Src) do begin
if CharInSet(Src[i], SafeChars) then
Result := Result + Src[i]
else
Result := Result + '%' + IntToHex(Ord(Src[i]), 2);
end;
end;

View File

@@ -273,7 +273,7 @@ procedure TfrmSQLhelp.ButtonOnlinehelpClick(Sender: TObject);
begin
// Link/redirect to mysql.com for further help
ShellExec( APPDOMAIN + 'sqlhelp.php?mysqlversion='+inttostr(MainForm.ActiveConnection.ServerVersionInt)+
'&keyword='+urlencode(keyword) );
'&keyword='+EncodeURL(keyword) );
end;