--- parser3/src/classes/image.C 2016/11/01 23:10:40 1.157 +++ parser3/src/classes/image.C 2017/05/11 21:09:42 1.161 @@ -1,7 +1,7 @@ /** @file Parser: @b image parser class. - Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -25,7 +25,7 @@ #include "pa_vdate.h" #include "pa_table.h" -volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.157 2016/11/01 23:10:40 moko Exp $"; +volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.161 2017/05/11 21:09:42 moko Exp $"; // defines @@ -736,28 +736,18 @@ static void _measure(Request& r, MethodP GET_SELF(r, VImage).set(file_name, width, height, 0, exif); } -#ifndef DOXYGEN -struct Attrib_info { - String* tag; ///< html tag being constructed - HashStringValue* skip; ///< tag attributes not to append to tag string [to skip] -}; -#endif -static void append_attrib_pair(HashStringValue::key_type key, HashStringValue::value_type value, Attrib_info* info) { - // skip user-specified, internal(starting with "line-") attributes and border attribute with empty value - if( - (info->skip && info->skip->get(key)) - || key.pos("line-")==0 - || (key=="border" && !value->is_defined()) - ) +static void append_attrib_pair(String &tag, String::Body key, Value* value){ + // skip border attribute with empty value + if(key=="border" && !value->is_defined()) return; // src="a.gif" width="123" ismap[=-1] - *info->tag << " " << key; + tag << " " << key; if(value->is_string() || value->as_int()>=0) - *info->tag << "=\"" << value->as_string() << "\""; + tag << "=\"" << value->as_string() << "\""; } -static void _html(Request& r, MethodParams& params) { +static void _html(Request& r, MethodParams& params) { String tag; tag << "for_each(append_attrib_pair, &info); + for(HashStringValue::Iterator i(*attribs); i; i.next() ) + append_attrib_pair(tag, i.key(), i.value()); } else throw Exception(PARSER_RUNTIME, 0, "attributes must be hash"); } } - { - Attrib_info info={&tag, attribs}; - fields.for_each(append_attrib_pair, &info); + for(HashStringValue::Iterator i(fields); i; i.next() ){ + String::Body key=i.key(); + // skip user-specified attributes + if(attribs && attribs->get(key)) + continue; + // allow only html attributes (to exclude exif, line-*) + if(key=="src" || key=="width" || key=="height" || key=="border") + append_attrib_pair(tag, key, i.value()); } + tag << " />"; r.write(tag); } @@ -787,7 +783,7 @@ static void _html(Request& r, MethodPara /// @test wrap FILE to auto-object static gdImage* load(Request& r, const String& file_name){ const char* file_name_cstr=r.absolute(file_name).taint_cstr(String::L_FILE_SPEC); - if(FILE *f=fopen(file_name_cstr, "rb")) { + if(FILE *f=pa_fopen(file_name_cstr, "rb")) { gdImage* image=new gdImage; bool ok=image->CreateFromGif(f); fclose(f); @@ -967,13 +963,13 @@ static void _polybar(Request& r, MethodP // Font class Font::Font(Charset& asource_charset, const String& aalphabet, gdImage* aifont, int aheight, int amonospace, int aspacebarspace, int aletterspacing): - fsource_charset(asource_charset), + letterspacing(aletterspacing), height(aheight), monospace(amonospace), spacebarspace(aspacebarspace), - letterspacing(aletterspacing), ifont(aifont), - alphabet(aalphabet) { + alphabet(aalphabet), + fsource_charset(asource_charset){ if(fsource_charset.isUTF8()){ size_t index=0;