Recent

Author Topic: TIpHtmlPanel bug introduced after version 1.8.5  (Read 682 times)

Soner

  • Sr. Member
  • ****
  • Posts: 280
TIpHtmlPanel bug introduced after version 1.8.5
« on: May 11, 2022, 11:47:58 am »
I noticed a new bug in TIpHtmlPanel. When you have comment-tags in css-part of html-file this css-part is ignored:

  <style type="text/css">
    <!--
    This part is ignored due the tag-comment.
   
    body{ font-size:9pt; font-family:Arial, Helvetica, sans-serif }
    table{ font-size:9pt; font-family:Arial, Helvetica, sans-serif }   
    -->
  </style>

It is worked in lazarus 1.8.5.

paweld

  • Sr. Member
  • ****
  • Posts: 404
Re: TIpHtmlPanel bug introduced after version 1.8.5
« Reply #1 on: May 11, 2022, 12:38:58 pm »
This is not a bug but correct parser behavior.
Best regards
paweld
---
Lazarus trunk / FPC stable

PascalDragon

  • Hero Member
  • *****
  • Posts: 4280
  • Compiler Developer
Re: TIpHtmlPanel bug introduced after version 1.8.5
« Reply #2 on: May 11, 2022, 01:27:59 pm »
This is not a bug but correct parser behavior.

Not quite. There are special rules for this situation.

wp

  • Hero Member
  • *****
  • Posts: 9899
Re: TIpHtmlPanel bug introduced after version 1.8.5
« Reply #3 on: May 12, 2022, 12:27:12 am »
Comparing the source code between Laz 1.8.4 and Laz/main, I see only irrelevant changes in TIpHtml.ParseStyle (removal of Delphi-related defines), and absolutely no change in TIpHtml.NextToken which (among a lot of other things) is responsible for removal of html comments.

Therefore, html-comment tags in css have been ignored by the IpHtmlPanel all the time (at least since v1.8.4).

What you see as difference between your v1.8.5 and the current version is (probably) due to different handling of the DefaultFontSize and DefaultTypeFace properties of the IpHtmlPanel which are used when no specifications for font size and type face are found in the html text (which is true here since the style is commented out).

PascalDragon

  • Hero Member
  • *****
  • Posts: 4280
  • Compiler Developer
Re: TIpHtmlPanel bug introduced after version 1.8.5
« Reply #4 on: May 12, 2022, 09:03:36 am »
Therefore, html-comment tags in css have been ignored by the IpHtmlPanel all the time (at least since v1.8.4).

Are the tags themselves ignored or is their content ignored as well? (just to clarify)

wp

  • Hero Member
  • *****
  • Posts: 9899
Re: TIpHtmlPanel bug introduced after version 1.8.5
« Reply #5 on: May 12, 2022, 09:51:21 am »
Sorry for being inaccurate. Whenever the scanner finds an opening html comment tag ('<!-') it ignores everything until the closing tag is found.

Excerpt from TIpHtmlPanel.NextToken:
Code: Pascal  [Select][+][-]
  1.     if Ch = '<' then begin
  2.       Ch := GetChar;
  3.       if Ch = '!' then begin
  4.         if GetChar = '-' then begin
  5.           if GetChar <> '-' then
  6.             if FlagErrors then
  7.               ReportError(SHtmlDashExp);
  8.           Ch := GetChar;
  9.           repeat
  10.             while Ch <> '-' do begin
  11.               if Ch = #0 then
  12.                 break;
  13.               Ch := GetChar;
  14.             end;
  15.             if (Ch = #0) then
  16.               break
  17.             else begin
  18.               Ch := GetChar;
  19.               if Ch = #0 then
  20.                 break;
  21.               if Ch = '-' then begin
  22.                 Ch := GetChar;
  23.                 while (Ch = '-') do
  24.                   Ch := GetChar;
  25.                 {if (Ch = #0) or (Ch = '>') then
  26.                   break;}
  27.                 while not (Ch in [#0,'>']) do
  28.                   Ch := GetChar;
  29.                 break;
  30.               end;
  31.             end;
  32.           until false;
  33.           CurToken := IpHtmlTagComment;
  34.         end else begin                  

PascalDragon

  • Hero Member
  • *****
  • Posts: 4280
  • Compiler Developer
Re: TIpHtmlPanel bug introduced after version 1.8.5
« Reply #6 on: May 12, 2022, 10:14:48 am »
Sorry for being inaccurate. Whenever the scanner finds an opening html comment tag ('<!-') it ignores everything until the closing tag is found.

Then according to the link I mentioned that would need to be changed for HTML4 and higher...

wp

  • Hero Member
  • *****
  • Posts: 9899
Re: TIpHtmlPanel bug introduced after version 1.8.5
« Reply #7 on: May 12, 2022, 10:17:23 am »
Patches are welcome.

Soner

  • Sr. Member
  • ****
  • Posts: 280
Re: TIpHtmlPanel bug introduced after version 1.8.5
« Reply #8 on: May 12, 2022, 06:36:36 pm »
Thanks for the answers.
I removed now the comments from css-parts.

Maybe IpHtml needs a variable like currentsection is css-part, javascript or html and ignore comment-tag in css/javascript sections.

wp thanks for the hint at the right place in the source code. But I have no time for inspecting this now, maybe later.

 

TinyPortal © 2005-2018