--- parser3/src/classes/image.C 2016/10/26 19:10:31 1.155 +++ 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.155 2016/10/26 19:10:31 moko Exp $"; +volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.161 2017/05/11 21:09:42 moko Exp $"; // defines @@ -527,7 +527,7 @@ static Value* parse_IFD_entry_value(bool { reader.seek(tiff_base+endian_to_uint(is_big, entry.value_or_offset_to_it), SEEK_SET); const char* value; - if(reader.read(value, value_size)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_pass_lang(tag); + r.write(tag); } /// @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); @@ -830,7 +826,7 @@ static void _gif(Request& r, MethodParam vfile.set_binary(false/*not tainted*/, (const char *)buf.ptr, buf.size, file_name, new VString(*new String("image/gif"))); - r.write_no_lang(vfile); + r.write(vfile); } static void _line(Request& r, MethodParams& params) { @@ -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; @@ -1117,7 +1113,7 @@ static void _length(Request& r, MethodPa const String& s=params.as_string(0, "text must not be code"); VImage& vimage=GET_SELF(r, VImage); - r.write_no_lang(*new VInt(vimage.font().string_width(s))); + r.write(*new VInt(vimage.font().string_width(s))); } static void _arc(Request& r, MethodParams& params) { @@ -1202,7 +1198,7 @@ static void _pixel(Request& r, MethodPar image.SetPixel(x, y, image.Color(params.as_int(2, "color must be int", r))); } else - r.write_no_lang(*new VInt(image.DecodeColor(image.GetPixel(x, y)))); + r.write(*new VInt(image.DecodeColor(image.GetPixel(x, y)))); }