mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 02:29:21 +02:00
Grids: fix decoding HTML entities when pasting HTML. Issue #0037258
git-svn-id: branches/fixes_2_0@63489 -
This commit is contained in:
parent
3877144c0a
commit
c39bc40c24
@ -34,7 +34,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
// RTL + FCL
|
// RTL + FCL
|
||||||
Classes, SysUtils, Types, TypInfo, Math, FPCanvas, HtmlDefs,
|
Classes, SysUtils, Types, TypInfo, Math, FPCanvas, HtmlDefs, StrUtils,
|
||||||
// LCL
|
// LCL
|
||||||
LCLStrConsts, LCLType, LCLIntf, Controls, Graphics, Forms,
|
LCLStrConsts, LCLType, LCLIntf, Controls, Graphics, Forms,
|
||||||
LMessages, StdCtrls, LResources, MaskEdit, Buttons, Clipbrd, Themes, imglist,
|
LMessages, StdCtrls, LResources, MaskEdit, Buttons, Clipbrd, Themes, imglist,
|
||||||
@ -11463,6 +11463,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TCustomStringGrid.SelectionSetHTML(TheHTML, TheText: String);
|
procedure TCustomStringGrid.SelectionSetHTML(TheHTML, TheText: String);
|
||||||
var
|
var
|
||||||
bStartCol, bStartRow, bCol, bRow: Integer;
|
bStartCol, bStartRow, bCol, bRow: Integer;
|
||||||
@ -11472,28 +11473,42 @@ var
|
|||||||
bCellData, bTagEnd: Boolean;
|
bCellData, bTagEnd: Boolean;
|
||||||
bStr, bEndStr: PChar;
|
bStr, bEndStr: PChar;
|
||||||
|
|
||||||
function ReplaceEntities(cSt: string): string;
|
function ReplaceEntities(const cSt: string): string;
|
||||||
var
|
var
|
||||||
o,a,b: pchar;
|
|
||||||
dName: widestring;
|
dName: widestring;
|
||||||
dEntity: WideChar;
|
dEntity: WideChar;
|
||||||
|
pAmp, pSemi, pStart: Integer;
|
||||||
begin
|
begin
|
||||||
|
//debugln(['ReplaceEntities: cSt=',cSt]);
|
||||||
|
Result := '';
|
||||||
|
if (cSt = '') then
|
||||||
|
Exit;
|
||||||
|
pStart := 1;
|
||||||
while true do begin
|
while true do begin
|
||||||
result := cSt;
|
//debugln([' pStart=',pStart]);
|
||||||
if cSt = '' then
|
pAmp := PosEx('&', cSt, pStart);
|
||||||
break;
|
if (pAmp > 0) then
|
||||||
o := @cSt[1];
|
pSemi := PosEx(';', cSt, pAmp);
|
||||||
a := strscan(o, '&');
|
if ((pAmp and pSemi) = 0) then begin
|
||||||
if a = nil then
|
//debugln(' pAmp or pSemi = 0');
|
||||||
break;
|
Result := Result + Copy(cSt, pStart, MaxInt);
|
||||||
b := strscan(a + 1, ';');
|
Exit;
|
||||||
if b = nil then
|
end;
|
||||||
break;
|
//debugln([' pAmp=',pAmp,', pSemi=',pSemi]);
|
||||||
dName := UTF8Decode(copy(cSt, a - o + 2, b - a - 1));
|
dName := Utf8Decode(Copy(cSt, pAmp + 1, pSemi - pAmp - 1));
|
||||||
|
//debugln([' dName=',Utf8Encode(dName)]);
|
||||||
|
Result := Result + Copy(cSt, pStart, pAmp - pStart);
|
||||||
|
pStart := pSemi + 1;
|
||||||
|
|
||||||
dEntity := ' ';
|
dEntity := ' ';
|
||||||
if ResolveHTMLEntityReference(dName, dEntity) then begin
|
if ResolveHTMLEntityReference(dName, dEntity) then begin
|
||||||
system.delete(cSt, a - o + 1, b - a + 1);
|
//debugln(['dEntity=',Utf8Encode(dEntity)]);
|
||||||
system.insert(UTF8Encode(dEntity), cSt, a - o + 1);
|
result := result + Utf8Encode(dEntity);
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
//illegal html entity
|
||||||
|
//debugln(' illegal html entity: replace with "?"');
|
||||||
|
Result := Result + '?';
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user