From 160ddc258dc261d74c95a371d592b9e60a9ef059 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 18 Jun 2014 23:18:28 +0000 Subject: [PATCH] added: to htmlfilter: the filter is able to recognize a special tag, default called: content between ... will not be filtered git-svn-id: svn://ttmath.org/publicrep/winix/trunk@955 e52654a7-88a9-db11-a3e9-0013d4bc506e --- core/config.cpp | 1 + core/config.h | 6 ++ core/htmlfilter.cpp | 129 ++++++++++++++++++++++++++++++++++------ core/htmlfilter.h | 19 +++++- functions/functions.cpp | 1 + functions/passwd.cpp | 5 ++ templates/templates.cpp | 1 + 7 files changed, 142 insertions(+), 20 deletions(-) diff --git a/core/config.cpp b/core/config.cpp index bf8fcd3..9f37010 100755 --- a/core/config.cpp +++ b/core/config.cpp @@ -202,6 +202,7 @@ void Config::AssignValues(bool stdout_is_closed) html_filter_tabs = Size(L"html_filter_tabs", 2); html_filter_orphans = Bool(L"html_filter_orphans", true); html_filter_orphans_mode_str = Text(L"html_filter_orphans_mode_str", L"nbsp"); + html_filter_nofilter_tag = Text(L"html_filter_nofilter_tag", L"nofilter"); locale_dir = Text(L"locale_dir"); locale_dir_default = Text(L"locale_dir_default"); diff --git a/core/config.h b/core/config.h index 99dcb41..8cbb7f8 100755 --- a/core/config.h +++ b/core/config.h @@ -224,6 +224,12 @@ public: std::wstring html_filter_orphans_mode_str; HTMLFilter::OrphanMode html_filter_orphans_mode; + // the html nofilter tag + // content betweeng these tags (opening and closing) will not be filtered + // and this tag will not be included in the html output + // default: nofilter + std::wstring html_filter_nofilter_tag; + // the url of a new empty item (if there is not the subject too) // !! IMPROVE ME should be moved to locale std::wstring item_url_empty; diff --git a/core/htmlfilter.cpp b/core/htmlfilter.cpp index 527fa48..cd7d4e9 100755 --- a/core/htmlfilter.cpp +++ b/core/htmlfilter.cpp @@ -10,6 +10,7 @@ #include "htmlfilter.h" + namespace Winix { @@ -198,6 +199,13 @@ void HTMLFilter::SafeMode(bool safe_mode_) } +void HTMLFilter::SetNoFilterTag(const std::wstring & tag_name) +{ + no_filter_tag = tag_name; +} + + + HTMLFilter::Item & HTMLFilter::GetItem(size_t i) { @@ -345,7 +353,6 @@ void HTMLFilter::PutLastTagWithClosingTag() { const wchar_t * start = pchar; - while( *pchar != 0 ) { if( IsOpeningTagMark() ) @@ -367,6 +374,31 @@ const wchar_t * start = pchar; } +// used with tags +void HTMLFilter::PutTextBetweenLastTagWithClosingTag() +{ +const wchar_t * start = pchar, * end = pchar; + + while( *pchar != 0 ) + { + if( IsOpeningTagMark() ) + { + if( IsClosingTagForLastItem() ) + { + PopStack(); + CheckNewLine(); + break; + } + } + else + { + pchar += 1; + end = pchar; + } + } + + Put(start, end); +} @@ -449,16 +481,34 @@ void HTMLFilter::ReadItemAttrValue(bool has_quote) { size_t i; + // sprawdzic to wszedzie bo teraz jest tablica attr_value.clear(); + attr_value_temp.clear(); - // !! moze dodac obsluge escepowania cudzyslowu? sprawdzic czy to jest dostepne w htmlu - for( i=0 ; *pchar && *pchar != '\"' && !IsClosingTagMark() && (has_quote || (*pchar!=10 && !IsWhite(*pchar)) ); ++i ) + // !! dodac obsluge pojedynczego cudzyslowu + + for(i=0 ; *pchar && *pchar != '\"' && !IsClosingTagMark() && (has_quote || (*pchar!=10 && !IsWhite(*pchar)) ); ++i ) { + if( *pchar==10 || IsWhite(*pchar) ) + { + if( !attr_value_temp.empty() ) + { + attr_value.push_back(attr_value_temp); + attr_value_temp.clear(); + } + } + else if( i < WINIX_HTMLFILTER_ATTR_VALUE_MAXLEN ) - attr_value += *pchar; + attr_value_temp += *pchar; ++pchar; } + + if( !attr_value_temp.empty() ) + { + attr_value.push_back(attr_value_temp); + attr_value_temp.clear(); + } } @@ -720,14 +770,22 @@ void HTMLFilter::PutClosingTagMark() +// !! zmienic na lepsza nazwe +// bo to nie zwraca true jesli tag jest safe bool HTMLFilter::IsTagSafe(const wchar_t * tag) { if( !safe_mode ) return true; + if( IsNameEqual(tag, no_filter_tag.c_str()) ) + return false; + static const wchar_t * unsafe_tags[] = { - L"script", L"iframe", L"frame", L"frameset", - L"applet", L"head", L"meta", L"html", L"link", L"body" + L"applet", L"base", L"body", + L"embed", L"head", L"html", + L"frame", L"frameset",L"iframe", + L"link", L"meta", L"param" + L"object", L"script" }; size_t len = sizeof(unsafe_tags) / sizeof(const wchar_t*); @@ -755,7 +813,8 @@ bool HTMLFilter::IsTagSafe(const std::wstring & tag) bool HTMLFilter::PutOpeningTag() { if( !IsTagSafe(LastItem().name) ) - // dodac tutaj skipniecie calego tagu + // !! IMPROVE ME + // !! dodac tutaj skipniecie calego tagu return false; PutOpeningTagMark(); @@ -945,6 +1004,9 @@ const wchar_t * last_non_white = pchar; bool HTMLFilter::PrintOpeningItem() { + if( IsNameEqual(no_filter_tag, LastItem().name) ) + return true; + if( last_new_line ) { PutNewLine(); @@ -981,6 +1043,8 @@ bool HTMLFilter::ReadItemAttr() pchar += 1; // skipping '=' SkipWhiteLines(); + + // !! dodac obsluge pojedynczego cudzyslowu bool has_quote = (*pchar == '\"'); if( has_quote ) @@ -1001,28 +1065,46 @@ bool HTMLFilter::CheckItemAttr() if( attr_has_value && IsNameEqual(L"lang", attr_name) ) { LastItem().porphans = 0; - attr_value_lower = attr_value; - ToLower(attr_value_lower); - OrphansTab::iterator i = orphans_tab.find(attr_value_lower); + if( !attr_value.empty() ) + { + // we are taking the first value only + attr_value_lower = attr_value[0]; + ToLower(attr_value_lower); - if( i != orphans_tab.end() ) - LastItem().porphans = &i->second; + OrphansTab::iterator i = orphans_tab.find(attr_value_lower); + + if( i != orphans_tab.end() ) + LastItem().porphans = &i->second; + } } return true; } -void HTMLFilter::PrinItemAttr() +void HTMLFilter::PrintItemAttr() { +size_t i; + + if( IsNameEqual(no_filter_tag, LastItem().name) ) + return; + Put(' '); Put(attr_name); if( attr_has_value ) { Put(L"=\""); - Put(attr_value); + + for(i=0 ; i and