LHelp bug: titles with a '&' alone, cause a "range check error".
Original Reporter info from Mantis: devEric69
-
Reporter name: devEric69
Original Reporter info from Mantis: devEric69
- Reporter name: devEric69
Description:
- compile lHelp.
- open user.chm avec lHelp.
==> there's a "Range chack error" abort because a title is called Keybord & Mouse.
Steps to reproduce:
In ChmSpecialParser.pas, line 67, ther's thisfunction FixEscapedHTML(AText: string): string;
Below, in the "Additional information" memo, I've pasted this corrected function (patch), so that it distinguishes now a '&' alone (as in the title of user.chm '6.4.2 Keybord & Mouse"), from a character belonging to the HTML grammar like ' ', or '<', etc., etc.
Additional information:
function FixEscapedHTML(AText: string): string;
var
i, iPosAmpersand, iLenAText: Integer;
bFoundClosureSemiColon: Boolean;
ampstr: string; sTemp: string;
ws: widestring;
entity: widechar;
begin
Result := '';
i := 1;
iLenAText:= Length(AText);
while i <= iLenAText do begin
if AText[i]='&' then begin
iPosAmpersand:= i;
ampStr := '';
inc(i);
while (i <= iLenAText) and (AText[i] <> ';') do begin
ampStr := ampStr + AText[i];
inc(i);
end;
//is there a Char ';', closing a possible HTML entity like '&{#x}~~~{~~};'?
bFoundClosureSemiColon:= False;
if (i > iLenAText) then begin
if (AText[i-1] = ';') then
bFoundClosureSemiColon := True
end
else begin
if (AText[i] = ';') then
bFoundClosureSemiColon := True;
end;
if bFoundClosureSemiColon then begin //so, if it's a possible HTML encoded character like "&xxx;" ...
ws := UTF8Encode(ampStr);
if ResolveHTMLEntityReference(ws, entity) then
Result := Result + UnicodeToUTF8(cardinal(entity))
else
Result := Result + '?';
end
else begin //so, if it's not an HTML entity ie it's only an ampersand alone
sTemp := RightStr(AText, iLenAText - (iPosAmpersand-1));
Result := Result + sTemp;
end
end
else
Result := Result + AText[i];
inc(i);
end;
end;
Mantis conversion info:
- Mantis ID: 36523
- OS: Ubuntu
- OS Build: 18.04
- Platform: Linux
- Version: 2.0.4
- Fixed in revision: r62510 (#55a41430)
- Monitored by: » devEric69 (devEric69)