--- parser3/src/classes/image.C 2017/02/06 16:17:12 1.159 +++ 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.159 2017/02/06 16:17:12 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); }