Commit 6b7cf083 authored by jan.koester's avatar jan.koester
Browse files

check attributes signs

parent 40f1ab72
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -1770,6 +1770,29 @@ SEARCHBYTAG:

void libhtmlpp::HtmlElement::setAttribute(const std::string &name, const std::string &value) {
    Attributes* cattr = nullptr;

    const char forbidden[] = {'\"','\0'};

    auto checkForbidden = [forbidden](const std::string &input){
        for(size_t i = 0; i<input.length(); ++i){
            for(size_t ii=0; forbidden[ii]!='\0'; ++ii){
                if(ii>i){
                    return false;
                }
                if(input[i]==forbidden[i]){
                    return true;
                }
            }
        }
        return false;
    };

    if(checkForbidden(name) || checkForbidden(value)){
        HTMLException e;
        e[HTMLException::Error] << "setAttribute " << name.c_str() << "forbidden sign is used !";
        throw e;
    }

    for (cattr= _firstAttr; cattr; cattr=cattr->_nextAttr) {
        if(name.size() == cattr->_Key.size() && std::equal(name.begin(),name.end(),cattr->_Key.begin())){
            cattr->_Value.clear();
@@ -1784,6 +1807,7 @@ void libhtmlpp::HtmlElement::setAttribute(const std::string &name, const std::st
            _firstAttr = new Attributes();
            _lastAttr = _firstAttr;
    }

    cattr = _lastAttr;
    std::copy(name.begin(),name.end(),std::back_inserter(cattr->_Key) );
    std::copy(value.begin(),value.end(),std::back_inserter(cattr->_Value));
+9 −8
Original line number Diff line number Diff line
# add_executable(csstest csstest.cpp )
# target_link_libraries(csstest htmlpp)
add_executable(csstest csstest.cpp )
target_link_libraries(csstest htmlpp)
#
# add_test(csstest csstest)
add_test(csstest csstest)

add_executable(htmlpagetest htmlpagetest.cpp)
target_link_libraries(htmlpagetest htmlpp-static)

#add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html)
#add_test(htmlpagetest_wrong htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/wrong.html)
add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/html4.html)
add_test(htmlpagetest_right htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html)
add_test(htmlpagetest_wrong htmlpagetest ${CMAKE_SOURCE_DIR}/test/htmlfiles/wrong.html)

set_property(TEST htmlpagetest_wrong PROPERTY WILL_FAIL TRUE )

add_executable(htmlcopytest htmlcopytest.cpp)
target_link_libraries(htmlcopytest htmlpp-static)

#add_test(htmlcopytest_right htmlcopytest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html)

#set_tests_properties(htmlpagetest_wrong PROPERTIES WILL_FAIL TRUE)
add_test(htmlcopytest_right htmlcopytest ${CMAKE_SOURCE_DIR}/test/htmlfiles/right.html)

add_executable(htmlinserttest htmlinserttest.cpp)
target_link_libraries(htmlinserttest htmlpp-static)
+3 −3
Original line number Diff line number Diff line
@@ -36,9 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
void *__dso_handle __attribute__((__visibility__("hidden"))) __attribute__((weak)) = nullptr;

int main(){
    // libhtmlpp::HtmlTable table;
    libhtmlpp::HtmlElement htmlel("div");
    try{
        // table.setAttribute("Style",":;(),+~'");
        htmlel.setAttribute("Style",":;(),+~'");
        std::cout  << Green << "Test Passed!" << NOCOLOR << std::endl;
    }catch(...){
        std::cout   << Red << "Test not Passed!" << NOCOLOR << std::endl;
@@ -46,7 +46,7 @@ int main(){
    }
    
    try{
        // table.setAttribute("Style", "\"");
        htmlel.setAttribute("Style", "\"");
        std::cout   << Red << "Test not Passed!" << NOCOLOR<< std::endl;
        return -1;
    }catch(...){