mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 16:19:28 +02:00
LHelp: Fix a range error when title has sole '&' (not an HTML entity). Issue #36523, patch from devEric69.
git-svn-id: trunk@62510 -
This commit is contained in:
parent
024bfa3ac1
commit
55a41430ed
@ -47,13 +47,13 @@ type
|
|||||||
constructor Create(ATreeView: TTreeView; ASitemap: TChmSiteMap; StopBoolean: PBoolean; AChm: TObject);
|
constructor Create(ATreeView: TTreeView; ASitemap: TChmSiteMap; StopBoolean: PBoolean; AChm: TObject);
|
||||||
procedure DoFill(ParentNode: TTreeNode);
|
procedure DoFill(ParentNode: TTreeNode);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LConvEncoding, LazUTF8, HTMLDefs;
|
LConvEncoding, LazUTF8, HTMLDefs;
|
||||||
|
|
||||||
function ToUTF8(AText: ansistring): String;
|
function ToUTF8(const AText: AnsiString): String;
|
||||||
var
|
var
|
||||||
encoding: String;
|
encoding: String;
|
||||||
begin
|
begin
|
||||||
@ -64,29 +64,37 @@ begin
|
|||||||
Result := AText;
|
Result := AText;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FixEscapedHTML(AText: string): string;
|
function FixEscapedHTML(const AText: String): String;
|
||||||
var
|
var
|
||||||
i: Integer;
|
AmpPos, i: Integer;
|
||||||
ampstr: string;
|
AmpStr: String;
|
||||||
ws: widestring;
|
ws: WideString;
|
||||||
entity: widechar;
|
Entity: WideChar;
|
||||||
begin
|
begin
|
||||||
Result := '';
|
Result := '';
|
||||||
i := 1;
|
i := 1;
|
||||||
while i <= Length(AText) do begin
|
while i <= Length(AText) do
|
||||||
if AText[i]='&' then begin
|
begin
|
||||||
ampStr := '';
|
if AText[i]='&' then
|
||||||
inc(i);
|
begin
|
||||||
while AText[i] <> ';' do begin
|
AmpPos:= i;
|
||||||
ampStr := ampStr + AText[i];
|
repeat
|
||||||
inc(i);
|
inc(i); // First round passes beyond '&', then search for ';'.
|
||||||
end;
|
until (i > Length(AText)) or (AText[i] = ';');
|
||||||
ws := UTF8Encode(ampStr);
|
if i > Length(AText) then
|
||||||
if ResolveHTMLEntityReference(ws, entity) then
|
// Not HTML Entity, only ampersand by itself. Copy the rest of AText at one go.
|
||||||
Result := Result + UnicodeToUTF8(cardinal(entity))
|
Result := Result + RightStr(AText, i-AmpPos)
|
||||||
else
|
else
|
||||||
Result := Result + '?';
|
begin // ';' was found, this may be an HTML entity like "&xxx;".
|
||||||
end else
|
AmpStr := Copy(AText, AmpPos+1, i-AmpPos-1);
|
||||||
|
ws := UTF8Encode(AmpStr);
|
||||||
|
if ResolveHTMLEntityReference(ws, Entity) then
|
||||||
|
Result := Result + UnicodeToUTF8(cardinal(Entity))
|
||||||
|
else
|
||||||
|
Result := Result + '?';
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
Result := Result + AText[i];
|
Result := Result + AText[i];
|
||||||
inc(i);
|
inc(i);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user