packages/fcl-base/src/uriparser.pp has
function EncodeURI(const URI: TURI): String;
// ! if no scheme then first colon in path should be escaped
begin
SetLength(Result, 0);
if Length(URI.Protocol) > 0 then
Result := LowerCase(URI.Protocol) + ':';
if URI.HasAuthority then
begin
Result := Result + '//';
if Length(URI.Username) > 0 then
begin
Result := Result + URI.Username;
if Length(URI.Password) > 0 then
Result := Result + ':' + URI.Password;
Result := Result + '@';
end;
Result := Result + URI.Host;
end;
if URI.Port <> 0 then
Result := Result + ':' + IntToStr(URI.Port);
Result := Result + Escape(URI.Path, ValidPathChars);
if Length(URI.Document) > 0 then
begin
if (Length(URI.Path) > 0) and ((Length(Result) = 0) or (Result[Length(Result)] <> '/')) then
Result := Result + '/';
Result := Result + Escape(URI.Document, ValidPathChars);
end;
if Length(URI.Params) > 0 then
Result := Result + '?' + Escape(URI.Params, ValidPathChars);
if Length(URI.Bookmark) > 0 then
Result := Result + '#' + Escape(URI.Bookmark, ValidPathChars);
end;
The initial "
SetLength(Result, 0);" line has been replaced with "
Result := '';".
All comparisons of
Length(string) with zero have been replaced by comparisons of string with ''.
The function becomes:
function EncodeURI(const URI: TURI): String;
// ! if no scheme then first colon in path should be escaped
begin
Result := '';
if URI.Protocol <> '' then
Result := LowerCase(URI.Protocol) + ':';
if URI.HasAuthority then
begin
Result := Result + '//';
if URI.Username <> '' then
begin
Result := Result + URI.Username;
if URI.Password <> '' then
Result := Result + ':' + URI.Password;
Result := Result + '@';
end;
Result := Result + URI.Host;
end;
if URI.Port <> 0 then
Result := Result + ':' + IntToStr(URI.Port);
Result := Result + Escape(URI.Path, ValidPathChars);
if URI.Document <> '' then
begin
if (URI.Path <> '') and ((Result = '') or (Result[Length(Result)] <> '/')) then
Result := Result + '/';
Result := Result + Escape(URI.Document, ValidPathChars);
end;
if URI.Params <> '' then
Result := Result + '?' + Escape(URI.Params, ValidPathChars);
if URI.Bookmark <> '' then
Result := Result + '#' + Escape(URI.Bookmark, ValidPathChars);
end;
The only comparison of a length of a string with zero in the entire file remained inside function
ParseURI, so that line has been modified from "
if Length(Authority)>0 then" to "
if Authority <> '' then".
A patch has been attached.