From 2585565b3e98fc17695f5eab52c04855038c130b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 29 Nov 2020 13:59:30 +0000 Subject: [PATCH] better test for output to target We used to enable write to stdout if the first character of an output filename was ".", eg.: vips copy x.jpg .png But this will also enable write to stdout for things like: vips copy x.jpg ./y.png This patch also tests that the rightmost "." in a filename is also the first character. Thanks barryspearce See https://github.com/libvips/libvips/issues/1906 --- ChangeLog | 1 + libvips/iofuncs/object.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2f6b12d1..292ba690 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ - check for overflow in gifload height [lovell] - fix msb_first default in ppm load and save [ewelot] - force binary mode on win for connection read / write [Alreiber] +- better testing for output to target [barryspearce] 6/9/20 started 8.10.2 - update magicksave/load profile handling [kelilevi] diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 36cccdf3..e8495c51 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -2176,6 +2176,17 @@ vips_object_print_arg( VipsObject *object, GParamSpec *pspec, VipsBuf *buf ) g_value_unset( &value ); } +/* Is a filename a target, ie. it is of the form ".jpg". Any trailing options + * have already been stripped. Watch out for cases like "./x.jpg". + */ +static gboolean +vips_filename_istarget( const char *filename ) +{ + const char *p; + + return( (p = strrchr( filename, '.' )) && p == filename ); +} + /* Write a named arg to the string. If the arg does not need a string (see * above), arg will be NULL. */ @@ -2209,7 +2220,7 @@ vips_object_get_argument_to_string( VipsObject *object, vips__filename_split8( arg, filename, option_string ); - if( vips_isprefix( ".", filename ) ) { + if( vips_filename_istarget( filename ) ) { VipsTarget *target; if( !(target = vips_target_new_to_descriptor( 1 )) )