* sax_html.pp, ignore markup in STYLE and SCRIPT elements, Mantis #18826

git-svn-id: trunk@17003 -
This commit is contained in:
sergei 2011-02-26 16:59:57 +00:00
parent 08fdb5af54
commit b7e26ed986

View File

@ -429,6 +429,18 @@ begin
WStrLower(result);
end;
function RightTrimmedLength(const s: SAXString): Integer;
begin
result := Length(s);
while IsXmlWhitespace(s[result]) do Dec(result);
end;
function TagPos(elTag: THTMLElementTag; s: SAXString): Integer;
begin
WStrLower(s);
Result := Pos(HTMLElementProps[elTag].Name, s);
end;
procedure THTMLReader.EnterNewScannerContext(NewContext: THTMLScannerContext);
var
Attr: TSAXAttributes;
@ -454,6 +466,20 @@ begin
end;
scTag:
if Length(TokenText) > 0 then
begin
{ ignore possibly unescaped markup in SCRIPT and STYLE }
if (FNesting > 0) and (FStack[FNesting-1] in [etScript,etStyle]) and
not (
(TokenText[1] = '/') and
(RightTrimmedLength(TokenText)=Length(HTMLElementProps[FStack[FNesting-1]].Name)+1) and
(TagPos(FStack[FNesting-1], TokenText) = 2)
)
and (TokenText[1] <> '!') then
begin
FTokenText := '<'+FTokenText+'>';
DoCharacters(PSAXChar(TokenText), 0, Length(TokenText));
end
else
begin
Attr := nil;
if TokenText[Length(fTokenText)]='/' then // handle xml/xhtml style empty tag
@ -496,6 +522,7 @@ begin
Attr.Free;
end;
end;
end;
FScannerContext := NewContext;
SetLength(FTokenText, 0);
FCurStringValueDelimiter := #0;