diff --git a/TODO b/TODO index a20ae074..c9790b1c 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -- can we hjave .svg.gz as a suffix? should be possible - - try: $ vips avg broken.jpg[fail] diff --git a/libvips/foreign/svgload.c b/libvips/foreign/svgload.c index 9fd813c9..aa055506 100644 --- a/libvips/foreign/svgload.c +++ b/libvips/foreign/svgload.c @@ -338,6 +338,7 @@ static const char *vips_foreign_svg_suffs[] = { */ #if LIBRSVG_CHECK_FEATURE(SVGZ) ".svgz", + ".svg.gz", #endif NULL }; @@ -482,7 +483,7 @@ vips_foreign_load_svg_is_a_buffer( const void *buf, size_t len ) return( FALSE ); for( i = 0; i < 200 && i < len - 5; i++ ) - if( strncasecmp( str + i, " m ) + return( FALSE ); + + return( strcasecmp( a + m - n, b ) == 0 ); +} + /* Test for string a starts string b. a is a known-good string, b may be * random data. */ @@ -461,30 +475,22 @@ int vips_filename_suffix_match( const char *path, const char *suffixes[] ) { char *basename; - char *suffix; char *q; - const char **p; int result; + const char **p; - /* Drop any directory components, we want ignore any '.' in there. + /* Drop any directory components. */ basename = g_path_get_basename( path ); - /* Zap any trailing options. + /* Zap any trailing [] options. */ if( (q = (char *) vips__find_rightmost_brackets( basename )) ) *q = '\0'; - /* And select just the '.' and to the right. - */ - if( (q = strrchr( basename, '.' )) ) - suffix = q; - else - suffix = basename; - result = 0; - for( p = suffixes; *p; p++ ) - if( g_ascii_strcasecmp( suffix, *p ) == 0 ) { + for( p = suffixes; *p; p++ ) + if( vips_iscasepostfix( basename, *p ) ) { result = 1; break; } diff --git a/test/images/vips-profile.svg.gz b/test/images/vips-profile.svg.gz new file mode 100644 index 00000000..8ccb610f Binary files /dev/null and b/test/images/vips-profile.svg.gz differ diff --git a/test/test_foreign.py b/test/test_foreign.py index 80a84d8d..edbf9802 100755 --- a/test/test_foreign.py +++ b/test/test_foreign.py @@ -51,6 +51,7 @@ class TestForeign(unittest.TestCase): self.cmyk_pdf_file = "images/cmyktest.pdf" self.svg_file = "images/vips-profile.svg" self.svgz_file = "images/vips-profile.svgz" + self.svg_gz_file = "images/vips-profile.svg.gz" self.colour = Vips.Image.jpegload(self.jpeg_file) self.mono = self.colour.extract_band(1) @@ -501,6 +502,8 @@ class TestForeign(unittest.TestCase): self.file_loader("svgload", self.svgz_file, svg_valid) self.buffer_loader("svgload_buffer", self.svgz_file, svg_valid) + self.file_loader("svgload", self.svg_gz_file, svg_valid) + im = Vips.Image.new_from_file(self.svg_file) x = Vips.Image.new_from_file(self.svg_file, scale = 2) self.assertLess(abs(im.width * 2 - x.width), 2)