added to HTMLFilter:

- now we can parse " and ' in html attributes
- we can skip html tags and commentaries, added method:
  void SkipAllTags(bool skip_all_tags, bool skip_commentaries);
- there is virtual method: virtual void ItemFound();
  which is called when a html tag is parsed




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1129 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
tomasz.sowa committed 2018-10-23 23:28:45 +00:00
1 parent d1e7765e98
commit 027a8ec428
3 files changed
+130 -69

No files matched your search

+1 -1
View File
@@ -1 +1 @@
winix.src.files = ./core/synchro.h ./core/sessioncontainer.h ./core/cookieparser.h ./core/misc.cpp ./core/item.cpp ./core/error.h ./core/timezone.h ./core/compress.h ./core/crypt.cpp ./core/dirs.cpp ./core/slog.cpp ./core/config.cpp ./core/lastcontainer.cpp ./core/users.h ./core/httpsimpleparser.cpp ./core/threadmanager.h ./core/postparser.h ./core/pluginmsg.h ./core/acceptbaseparser.h ./core/loadavg.cpp ./core/job.h ./core/mountparser.cpp ./core/timezones.h ./core/sessionmanager.h ./core/groups.h ./core/system.cpp ./core/rebus.h ./core/synchro.cpp ./core/lock.cpp ./core/acceptencodingparser.h ./core/version.h ./core/compress.cpp ./core/ipbancontainer.cpp ./core/request.h ./core/plugindata.h ./core/plugin.cpp ./core/sessionparser.cpp ./core/bbcodeparser.h ./core/users.cpp ./core/mount.cpp ./core/item.h ./core/slog.h ./core/threadmanager.cpp ./core/acceptbaseparser.cpp ./core/lastcontainer.h ./core/httpsimpleparser.h ./core/timezones.cpp ./core/groups.cpp ./core/requesttypes.h ./core/system.h ./core/bbcodeparser.cpp ./core/lock.h ./core/ipbancontainer.h ./core/group.h ./core/plugin.h ./core/run.cpp ./core/textstream.h ./core/sessionparser.h ./core/basethread.h ./core/mount.h ./core/htmlfilter.cpp ./core/user.cpp ./core/app.cpp ./core/image.cpp ./core/ugcontainer.h ./core/postmultiparser.h ./core/logmanipulators.h ./core/sessioncontainer.cpp ./core/dircontainer.h ./core/log.h ./core/session.h ./core/timezone.cpp ./core/mounts.h ./core/ipban.h ./core/cur.h ./core/misc.h ./core/dirs.h ./core/crypt.h ./core/run.h ./core/config.h ./core/job.cpp ./core/postmultiparser.cpp ./core/sessionmanager.cpp ./core/htmlfilter.h ./core/rebus.cpp ./core/dircontainer.cpp ./core/log.cpp ./core/user.h ./core/loadavg.h ./core/session.cpp ./core/mountparser.h ./core/mounts.cpp ./core/image.h ./core/plugindata.cpp ./core/request.cpp ./core/app.h ./core/basethread.cpp ./core/sessionidmanager.h ./core/winix_const.h ./core/sessionidmanager.cpp ./db/dbconn.cpp ./db/db.cpp ./db/dbbase.h ./db/dbitemcolumns.cpp ./db/dbtextstream.cpp ./db/dbconn.h ./db/db.h ./db/dbitemcolumns.h ./db/dbitemquery.cpp ./db/dbtextstream.h ./db/dbitemquery.h ./db/dbbase.cpp ./functions/upload.cpp ./functions/priv.h ./functions/env.cpp ./functions/default.h ./functions/node.h ./functions/specialdefault.h ./functions/timezone.cpp ./functions/pw.h ./functions/adduser.h ./functions/chmod.h ./functions/imgcrop.cpp ./functions/vim.h ./functions/account.h ./functions/mount.cpp ./functions/uptime.cpp ./functions/ckeditor.cpp ./functions/mkdir.cpp ./functions/reload.cpp ./functions/functionparser.h ./functions/logout.cpp ./functions/rmuser.cpp ./functions/rm.cpp ./functions/chown.h ./functions/nicedit.h ./functions/mv.h ./functions/node.cpp ./functions/specialdefault.cpp ./functions/adduser.cpp ./functions/upload.h ./functions/vim.cpp ./functions/env.h ./functions/timezone.h ./functions/who.h ./functions/cp.cpp ./functions/run.cpp ./functions/locale.h ./functions/imgcrop.h ./functions/passwd.h ./functions/mount.h ./functions/privchanger.cpp ./functions/functions.cpp ./functions/last.h ./functions/ckeditor.h ./functions/mkdir.h ./functions/reload.h ./functions/cat.h ./functions/download.h ./functions/ln.h ./functions/nicedit.cpp ./functions/functionbase.cpp ./functions/man.h ./functions/rm.h ./functions/meta.cpp ./functions/emacs.cpp ./functions/sort.h ./functions/who.cpp ./functions/ipban.h ./functions/locale.cpp ./functions/passwd.cpp ./functions/last.cpp ./functions/subject.h ./functions/download.cpp ./functions/cp.h ./functions/cat.cpp ./functions/login.cpp ./functions/tinymce.cpp ./functions/ln.cpp ./functions/run.h ./functions/uname.h ./functions/man.cpp ./functions/functions.h ./functions/privchanger.h ./functions/ls.cpp ./functions/template.h ./functions/stat.h ./functions/priv.cpp ./functions/default.cpp ./functions/functionbase.h ./functions/pw.cpp ./functions/sort.cpp ./functions/ipban.cpp ./functions/chmod.cpp ./functions/meta.h ./functions/account.cpp ./functions/emacs.h ./functions/subject.cpp ./functions/functionparser.cpp ./functions/uname.cpp ./functions/uptime.h ./functions/template.cpp ./functions/stat.cpp ./functions/tinymce.h ./functions/login.h ./functions/chown.cpp ./functions/logout.h ./functions/mv.cpp ./functions/rmuser.h ./functions/ls.h ./main/main.cpp ./notify/notifypool.h ./notify/templatesnotify.cpp ./notify/notify.cpp ./notify/templatesnotify.h ./notify/notify.h ./notify/notifythread.cpp ./notify/notifypool.cpp ./notify/notifythread.h ./plugins/group/init.cpp ./plugins/group/groups.h ./plugins/group/groupinfo.cpp ./plugins/group/groupinfo.h ./plugins/group/templates.cpp ./plugins/group/groups.cpp ./plugins/stats/statssession.h ./plugins/stats/bot.h ./plugins/stats/stats.cpp ./plugins/stats/templates.cpp ./plugins/s Line truncated winix.src.files = ./templates/miscspace.h ./templates/generic.cpp ./templates/sys.cpp ./templates/user.cpp ./templates/currentdate.cpp ./templates/textextstream.cpp ./templates/upload.cpp ./templates/patterncacher.h ./templates/env.cpp ./templates/indexpatterns.cpp ./templates/htmltextstream.h ./templates/who.cpp ./templates/locale.cpp ./templates/misc.h ./templates/patterns.cpp ./templates/passwd.cpp ./templates/mount.cpp ./templates/templates.h ./templates/last.cpp ./templates/uptime.cpp ./templates/insert.cpp ./templates/doc.cpp ./templates/changepatterns.cpp ./templates/server.cpp ./templates/miscspace.cpp ./templates/login.cpp ./templates/filters.cpp ./templates/localefilter.h ./templates/man.cpp ./templates/ls.cpp ./templates/dir.cpp ./templates/priv.cpp ./templates/rebus.cpp ./templates/patterncacher.cpp ./templates/htmltextstream.cpp ./templates/textextstream.h ./templates/adduser.cpp ./templates/ipban.cpp ./templates/misc.cpp ./templates/indexpatterns.h ./templates/item.cpp ./templates/templates.cpp ./templates/winix.cpp ./templates/slog.cpp ./templates/locale.h ./templates/patterns.h ./templates/config.cpp ./templates/localefilter.cpp ./templates/changepatterns.h ./templates/stat.cpp ./templates/template.cpp ./templates/antispam.cpp ./plugins/mailregister/funregistermail_showusers.h ./plugins/mailregister/mdb.h ./plugins/mailregister/registermail_info.h ./plugins/mailregister/templates.cpp ./plugins/mailregister/funregistermail.cpp ./plugins/mailregister/funregistermail_showusers.cpp ./plugins/mailregister/mdb.cpp ./plugins/mailregister/registermail_info.cpp ./plugins/mailregister/init.cpp ./plugins/mailregister/funregistermail.h ./plugins/thread/tdb.cpp ./plugins/thread/pluginmsg.h ./plugins/thread/thread.h ./plugins/thread/tdb.h ./plugins/thread/funthread.cpp ./plugins/thread/threadinfo.cpp ./plugins/thread/funthread.h ./plugins/thread/threadinfo.h ./plugins/thread/createthread.cpp ./plugins/thread/reply.cpp ./plugins/thread/showthreads.cpp ./plugins/thread/templates.cpp ./plugins/thread/createthread.h ./plugins/thread/reply.h ./plugins/thread/showthreads.h ./plugins/thread/init.cpp ./plugins/thread/templates.h ./plugins/group/groupinfo.h ./plugins/group/templates.cpp ./plugins/group/groups.cpp ./plugins/group/init.cpp ./plugins/group/groups.h ./plugins/group/groupinfo.cpp ./plugins/stats/bot.cpp ./plugins/stats/statssession.h ./plugins/stats/bot.h ./plugins/stats/stats.cpp ./plugins/stats/templates.cpp ./plugins/stats/init.cpp ./plugins/stats/stats.h ./plugins/stats/templates.h ./plugins/gallery/gallery.h ./plugins/gallery/galleryinfo.cpp ./plugins/gallery/templates.cpp ./plugins/gallery/gallery.cpp ./plugins/gallery/galleryinfo.h ./plugins/gallery/init.cpp ./plugins/export/init.cpp ./plugins/export/export.h ./plugins/export/exportthread.cpp ./plugins/export/message.h ./plugins/export/edb.cpp ./plugins/export/funexport.cpp ./plugins/export/exportinfo.cpp ./plugins/export/exportthread.h ./plugins/export/edb.h ./plugins/export/funexport.h ./plugins/export/exportinfo.h ./plugins/ticket/sessiondata.h ./plugins/ticket/ticket.h ./plugins/ticket/editticket.cpp ./plugins/ticket/funticket.cpp ./plugins/ticket/templates.cpp ./plugins/ticket/editticket.h ./plugins/ticket/ticketinfo.cpp ./plugins/ticket/funticket.h ./plugins/ticket/init.cpp ./plugins/ticket/ticketinfo.h ./plugins/ticket/createticket.cpp ./plugins/ticket/showtickets.cpp ./plugins/ticket/tdb.cpp ./plugins/ticket/pluginmsg.h ./plugins/ticket/showtickets.h ./plugins/ticket/createticket.h ./plugins/ticket/sessiondata.cpp ./plugins/ticket/tdb.h ./plugins/menu/cache.cpp ./plugins/menu/init.cpp ./plugins/menu/cache.h ./plugins/menu/templates.cpp ./main/main.cpp ./db/dbbase.cpp ./db/dbconn.cpp ./db/db.cpp ./db/dbbase.h ./db/dbitemcolumns.cpp ./db/dbtextstream.cpp ./db/dbconn.h ./db/db.h ./db/dbitemcolumns.h ./db/dbitemquery.cpp ./db/dbtextstream.h ./db/dbitemquery.h ./core/loadavg.h ./core/session.cpp ./core/user.h ./core/mountparser.h ./core/mounts.cpp ./core/app.h ./core/image.h ./core/plugindata.cpp ./core/request.cpp ./core/synchro.h ./core/sessioncontainer.h ./core/cookieparser.h ./core/misc.cpp ./core/error.h ./core/item.cpp ./core/timezone.h ./core/compress.h ./core/dirs.cpp ./core/crypt.cpp ./core/slog.cpp ./core/config.cpp ./core/users.h ./core/lastcontainer.cpp ./core/httpsimpleparser.cpp ./core/postparser.h ./core/threadmanager.h ./core/pluginmsg.h ./core/acceptbaseparser.h ./core/loadavg.cpp ./core/mountparser.cpp ./core/job.h ./core/timezones.h ./core/sessionmanager.h ./core/groups.h ./core/system.cpp ./core/rebus.h ./core/synchro.cpp ./core/lock.cpp ./core/acceptencodingparser.h ./core/version.h ./core/compress.cpp ./core/ipbancontainer.cpp ./core/request.h ./core/plugindata.h ./core/plugin.cpp ./core/sessionparser.cpp ./core/sessionidmanager.h Line truncated
+117 -63
View File
@@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2008-2014, Tomasz Sowa * Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -97,17 +97,25 @@ size_t out_projected_len = in.size() * 2 + 1;
} }
HTMLFilter::HTMLFilter() void HTMLFilter::SetSomeDefaults()
{ {
pstack = new Item[WINIX_HTMLFILTER_STACK_MAXLEN];
buffer = new wchar_t[WINIX_HTMLFILTER_BUFFER_MAXLEN];
tab_size = 2; tab_size = 2;
trim_white = false; trim_white = false;
break_after = 0; break_after = 0;
wrap_line = 0; wrap_line = 0;
orphan_mode = orphan_nbsp; orphan_mode = orphan_nbsp;
safe_mode = false; safe_mode = false;
skip_all_tags = false;
skip_commentaries = false;
}
HTMLFilter::HTMLFilter()
{
pstack = new Item[WINIX_HTMLFILTER_STACK_MAXLEN];
buffer = new wchar_t[WINIX_HTMLFILTER_BUFFER_MAXLEN];
SetSomeDefaults();
} }
@@ -116,6 +124,8 @@ HTMLFilter::HTMLFilter(const HTMLFilter & f)
// don't need to copy the stack // don't need to copy the stack
pstack = new Item[WINIX_HTMLFILTER_STACK_MAXLEN]; pstack = new Item[WINIX_HTMLFILTER_STACK_MAXLEN];
buffer = new wchar_t[WINIX_HTMLFILTER_BUFFER_MAXLEN]; buffer = new wchar_t[WINIX_HTMLFILTER_BUFFER_MAXLEN];
SetSomeDefaults();
} }
@@ -125,6 +135,8 @@ HTMLFilter & HTMLFilter::operator=(const HTMLFilter & f)
pstack = new Item[WINIX_HTMLFILTER_STACK_MAXLEN]; pstack = new Item[WINIX_HTMLFILTER_STACK_MAXLEN];
buffer = new wchar_t[WINIX_HTMLFILTER_BUFFER_MAXLEN]; buffer = new wchar_t[WINIX_HTMLFILTER_BUFFER_MAXLEN];
// we can copy some fields from f
return *this; return *this;
} }
@@ -136,6 +148,8 @@ HTMLFilter::~HTMLFilter()
} }
void HTMLFilter::BreakWord(size_t break_after_) void HTMLFilter::BreakWord(size_t break_after_)
{ {
break_after = break_after_; break_after = break_after_;
@@ -224,6 +238,13 @@ void HTMLFilter::SafeMode(bool safe_mode_)
} }
void HTMLFilter::SkipAllTags(bool skip_all_tags, bool skip_commentaries)
{
this->skip_all_tags = skip_all_tags;
this->skip_commentaries = skip_commentaries;
}
void HTMLFilter::SetNoFilterTag(const std::wstring & tag_name) void HTMLFilter::SetNoFilterTag(const std::wstring & tag_name)
{ {
no_filter_tag = tag_name; no_filter_tag = tag_name;
@@ -374,9 +395,10 @@ return false;
// used for such tags as: script, pre, textarea // used for such tags as: script, pre, textarea
void HTMLFilter::PutLastTagWithClosingTag() void HTMLFilter::PutEverythingUntilClosingTag(bool put_closing_tag_as_well)
{ {
const wchar_t * start = pchar; const wchar_t * start = pchar;
const wchar_t * end = pchar;
while( *pchar != 0 ) while( *pchar != 0 )
{ {
@@ -384,32 +406,9 @@ const wchar_t * start = pchar;
{ {
if( IsClosingTagForLastItem() ) if( IsClosingTagForLastItem() )
{ {
PopStack(); if( put_closing_tag_as_well )
CheckNewLine(); end = pchar;
break;
}
}
else
{
pchar += 1;
}
}
Put(start, pchar);
}
// used with <nofilter> </nofilter> tags
void HTMLFilter::PutTextBetweenLastTagWithClosingTag()
{
const wchar_t * start = pchar, * end = pchar;
while( *pchar != 0 )
{
if( IsOpeningTagMark() )
{
if( IsClosingTagForLastItem() )
{
PopStack(); PopStack();
CheckNewLine(); CheckNewLine();
break; break;
@@ -427,16 +426,36 @@ const wchar_t * start = pchar, * end = pchar;
void HTMLFilter::SkipAndCheckClosingTag() void HTMLFilter::SkipAndCheckClosingTag()
{ {
bool is_quoted = false;
wchar_t quote_char = 0;
for( ; *pchar ; ++pchar ) for( ; *pchar ; ++pchar )
{ {
if( LastItem().type == Item::opening && IsClosingXmlSimpleTagMark() ) // closing xml tag: default '/' if( *pchar == '"' || *pchar == '\'' )
{
if( is_quoted )
{
if( *pchar == quote_char )
{
is_quoted = false;
}
}
else
{
is_quoted = true;
quote_char = *pchar;
}
}
else
if( !is_quoted && LastItem().type == Item::opening && IsClosingXmlSimpleTagMark() ) // closing xml tag: default '/'
{ {
LastItem().type = Item::simple; LastItem().type = Item::simple;
} }
else
if( IsClosingTagMark() ) if( !is_quoted && IsClosingTagMark() )
{ {
++pchar; ++pchar;
break; break;
@@ -502,18 +521,26 @@ size_t i;
void HTMLFilter::ReadItemAttrValue(bool has_quote) void HTMLFilter::ReadItemAttrValue(bool has_quote, wchar_t quote_char)
{ {
size_t i; size_t i;
// sprawdzic to wszedzie bo teraz jest tablica
attr_value.clear(); attr_value.clear();
attr_value_temp.clear(); attr_value_temp.clear();
// !! dodac obsluge pojedynczego cudzyslowu for(i=0 ; *pchar ; ++i, ++pchar )
for(i=0 ; *pchar && *pchar != '\"' && !IsClosingTagMark() && (has_quote || (*pchar!=10 && !IsWhite(*pchar)) ); ++i )
{ {
if( has_quote )
{
if( *pchar == quote_char )
break;
}
else
{
if( IsClosingTagMark() || *pchar == 10 || IsWhite(*pchar) )
break;
}
if( *pchar==10 || IsWhite(*pchar) ) if( *pchar==10 || IsWhite(*pchar) )
{ {
if( !attr_value_temp.empty() ) if( !attr_value_temp.empty() )
@@ -524,9 +551,9 @@ size_t i;
} }
else else
if( i < WINIX_HTMLFILTER_ATTR_VALUE_MAXLEN ) if( i < WINIX_HTMLFILTER_ATTR_VALUE_MAXLEN )
{
attr_value_temp += *pchar; attr_value_temp += *pchar;
}
++pchar;
} }
if( !attr_value_temp.empty() ) if( !attr_value_temp.empty() )
@@ -795,8 +822,8 @@ void HTMLFilter::PutClosingTagMark()
// !! zmienic na lepsza nazwe // !! IMPROVE ME change to a better name
// bo to nie zwraca true jesli tag jest safe // this functions does not return true when the tag is safe
bool HTMLFilter::IsTagSafe(const wchar_t * tag) bool HTMLFilter::IsTagSafe(const wchar_t * tag)
{ {
if( !safe_mode ) if( !safe_mode )
@@ -838,9 +865,10 @@ bool HTMLFilter::IsTagSafe(const std::wstring & tag)
bool HTMLFilter::PutOpeningTag() bool HTMLFilter::PutOpeningTag()
{ {
if( !IsTagSafe(LastItem().name) ) if( !IsTagSafe(LastItem().name) )
// !! IMPROVE ME {
// !! dodac tutaj skipniecie calego tagu SkipAndCheckClosingTag();
return false; return false;
}
PutOpeningTagMark(); PutOpeningTagMark();
Put(LastItem().name); Put(LastItem().name);
@@ -852,7 +880,7 @@ return true;
void HTMLFilter::PutClosingTag(const wchar_t * tag) void HTMLFilter::PutClosingTag(const wchar_t * tag)
{ {
if( !IsTagSafe(tag) ) if( skip_all_tags || !IsTagSafe(tag) )
return; return;
PutOpeningTagMark(); PutOpeningTagMark();
@@ -1005,9 +1033,19 @@ const wchar_t * last_non_white = pchar;
while( *pchar != 0 ) while( *pchar != 0 )
{ {
const wchar_t * commentary_start = pchar;
if( SkipCommentaryTagIfExists() ) if( SkipCommentaryTagIfExists() )
{ {
last_non_white = pchar - 1; // pointing at the last '>' from a commentary last_non_white = pchar - 1; // pointing at the last '>' from a commentary
PutNormalText(start, commentary_start);
if( !skip_commentaries )
{
PutNormalText(commentary_start, pchar);
}
start = pchar;
} }
else else
{ {
@@ -1029,7 +1067,7 @@ const wchar_t * last_non_white = pchar;
bool HTMLFilter::PrintOpeningItem() bool HTMLFilter::PrintOpeningItem()
{ {
if( IsNameEqual(no_filter_tag, LastItem().name) ) if( skip_all_tags || IsNameEqual(no_filter_tag, LastItem().name) )
return true; return true;
if( last_new_line ) if( last_new_line )
@@ -1068,16 +1106,15 @@ bool HTMLFilter::ReadItemAttr()
pchar += 1; // skipping '=' pchar += 1; // skipping '='
SkipWhiteLines(); SkipWhiteLines();
bool has_quote = (*pchar == '\"' || *pchar == '\'');
// !! dodac obsluge pojedynczego cudzyslowu wchar_t quote_char = *pchar;
bool has_quote = (*pchar == '\"');
if( has_quote ) if( has_quote )
pchar += 1; // skipping the first quote mark pchar += 1; // skipping the first quote mark
ReadItemAttrValue(has_quote); ReadItemAttrValue(has_quote, quote_char);
if( *pchar == '\"' ) if( has_quote && *pchar == quote_char )
pchar += 1; // skipping the last quote mark pchar += 1; // skipping the last quote mark
return true; return true;
@@ -1112,7 +1149,7 @@ void HTMLFilter::PrintItemAttr()
{ {
size_t i; size_t i;
if( IsNameEqual(no_filter_tag, LastItem().name) ) if( skip_all_tags || IsNameEqual(no_filter_tag, LastItem().name) )
return; return;
Put(' '); Put(' ');
@@ -1150,11 +1187,17 @@ void HTMLFilter::ReadItemClosing()
void HTMLFilter::ReadItemSpecial() void HTMLFilter::ReadItemSpecial()
{ {
LastItem().type = Item::special; LastItem().type = Item::special;
PutOpeningTagMark();
if( !skip_all_tags )
PutOpeningTagMark();
const wchar_t * start = pchar; const wchar_t * start = pchar;
pchar += 1; // skipping '!'
ReadItemName();
SkipAndCheckClosingTag(); SkipAndCheckClosingTag();
if( pchar > start ) if( !skip_all_tags && pchar > start )
Put(start, pchar); Put(start, pchar);
// closing tag mark is printed directly from the source // closing tag mark is printed directly from the source
@@ -1176,7 +1219,7 @@ void HTMLFilter::ReadItemOpening()
SkipAndCheckClosingTag(); // here LastItem().type can be changed to 'simple' SkipAndCheckClosingTag(); // here LastItem().type can be changed to 'simple'
if( !IsNameEqual(no_filter_tag, LastItem().name) ) if( !skip_all_tags && !IsNameEqual(no_filter_tag, LastItem().name) )
{ {
if( LastItem().type == Item::simple ) if( LastItem().type == Item::simple )
Put(L" /"); Put(L" /");
@@ -1187,6 +1230,11 @@ void HTMLFilter::ReadItemOpening()
} }
void HTMLFilter::ItemFound()
{
}
bool HTMLFilter::ReadItem() bool HTMLFilter::ReadItem()
{ {
if( *pchar == 0 ) if( *pchar == 0 )
@@ -1209,6 +1257,8 @@ bool HTMLFilter::ReadItem()
CheckNewLine(); CheckNewLine();
LastItem().new_line = last_new_line; LastItem().new_line = last_new_line;
ItemFound();
return true; return true;
} }
@@ -1332,13 +1382,13 @@ void HTMLFilter::CheckExceptions()
// in safe_mode the script tag is ignored // in safe_mode the script tag is ignored
if( !safe_mode && IsLastTag(L"script") ) if( !safe_mode && IsLastTag(L"script") )
PutLastTagWithClosingTag(); PutEverythingUntilClosingTag(!skip_all_tags);
if( IsLastTag(L"pre") || IsLastTag(L"textarea") ) if( IsLastTag(L"pre") || IsLastTag(L"textarea") )
PutLastTagWithClosingTag(); PutEverythingUntilClosingTag(!skip_all_tags);
if( IsLastTag(no_filter_tag) ) if( IsLastTag(no_filter_tag) )
PutTextBetweenLastTagWithClosingTag(); PutEverythingUntilClosingTag(false);
if( IsLastTag(L"body") ) if( IsLastTag(L"body") )
LastItem().has_body_tag = true; LastItem().has_body_tag = true;
@@ -1371,7 +1421,7 @@ int i;
for(int z=(int)stack_len-2 ; z>=i ; --z) for(int z=(int)stack_len-2 ; z>=i ; --z)
{ {
if( pstack[z].new_line ) if( !skip_all_tags && pstack[z].new_line )
{ {
PutNewLine(); PutNewLine();
PutTabs(z); PutTabs(z);
@@ -1421,7 +1471,7 @@ void HTMLFilter::CheckClosingTags()
if( IsNameEqual(pstack[stack_len-1].name, pstack[stack_len-2].name) ) if( IsNameEqual(pstack[stack_len-1].name, pstack[stack_len-2].name) )
{ {
// last closing tag is from the previous one // last closing tag is from the previous one
if( pstack[stack_len-2].new_line ) if( !skip_all_tags && pstack[stack_len-2].new_line )
{ {
PutNewLine(); PutNewLine();
PutTabs(stack_len-2); PutTabs(stack_len-2);
@@ -1444,7 +1494,7 @@ bool HTMLFilter::PrintRest()
const wchar_t * start = pchar; const wchar_t * start = pchar;
// in safe mode we do not print the rest html code // in safe mode we do not print the rest html code
if( safe_mode ) if( safe_mode || skip_all_tags )
return false; return false;
while( *pchar ) while( *pchar )
@@ -1474,7 +1524,7 @@ void HTMLFilter::ReadLoop()
{ {
if( stack_len > 1 ) if( stack_len > 1 )
{ {
pstack[stack_len-2].new_line = LastItem().new_line; //pstack[stack_len-2].new_line = LastItem().new_line;
} }
else else
if( trim_white ) if( trim_white )
@@ -1492,6 +1542,10 @@ void HTMLFilter::ReadLoop()
{ {
CheckClosingTags(); CheckClosingTags();
} }
else
{
PopStack();
}
ReadNormalText(); ReadNormalText();
} }
+12 -5
View File
@@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2008-2014, Tomasz Sowa * Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -99,7 +99,7 @@ public:
HTMLFilter(); HTMLFilter();
HTMLFilter(const HTMLFilter & f); HTMLFilter(const HTMLFilter & f);
HTMLFilter & operator=(const HTMLFilter & f); HTMLFilter & operator=(const HTMLFilter & f);
~HTMLFilter(); virtual ~HTMLFilter();
// main methods used for filtering // main methods used for filtering
@@ -156,6 +156,9 @@ public:
// (script, iframe, frame, frameset, applet, head, meta, html, link, body, ...) // (script, iframe, frame, frameset, applet, head, meta, html, link, body, ...)
void SafeMode(bool safe_mode_); void SafeMode(bool safe_mode_);
// skip all html tags
// gives only text without markup
void SkipAllTags(bool skip_all_tags, bool skip_commentaries);
protected: protected:
@@ -239,10 +242,13 @@ protected:
virtual void PutNormalText(const wchar_t * str, const wchar_t * end); virtual void PutNormalText(const wchar_t * str, const wchar_t * end);
virtual void ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white); virtual void ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white);
virtual void ItemFound();
/* /*
others others
*/ */
void SetSomeDefaults();
Item & GetItem(size_t i); Item & GetItem(size_t i);
Item & LastItem(); Item & LastItem();
@@ -288,7 +294,7 @@ protected:
bool PrintOpeningItem(); bool PrintOpeningItem();
void ReadItemName(); void ReadItemName();
void ReadItemAttrName(); void ReadItemAttrName();
void ReadItemAttrValue(bool has_quote); void ReadItemAttrValue(bool has_quote, wchar_t quote_char);
bool ReadItemAttr(); bool ReadItemAttr();
bool CheckItemAttr(); bool CheckItemAttr();
@@ -307,8 +313,7 @@ protected:
bool HasSemiloconAround(const wchar_t * str, const wchar_t * end); bool HasSemiloconAround(const wchar_t * str, const wchar_t * end);
void PutNormalNonWhite(const wchar_t * & str, const wchar_t * end); void PutNormalNonWhite(const wchar_t * & str, const wchar_t * end);
void PutNormalWhite(const wchar_t * & str, const wchar_t * end); void PutNormalWhite(const wchar_t * & str, const wchar_t * end);
void PutLastTagWithClosingTag(); void PutEverythingUntilClosingTag(bool put_closing_tag_as_well);
void PutTextBetweenLastTagWithClosingTag();
void PutTabs(size_t len); void PutTabs(size_t len);
void PutNonBreakingSpace(); void PutNonBreakingSpace();
void PutNewLine(); void PutNewLine();
@@ -335,6 +340,8 @@ protected:
size_t line_len; //length of the current line (without first spaces which create the html tree) size_t line_len; //length of the current line (without first spaces which create the html tree)
bool safe_mode; // skipping some unsafe tags bool safe_mode; // skipping some unsafe tags
Orphans orphans_temp; Orphans orphans_temp;
bool skip_all_tags;
bool skip_commentaries;
}; };