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
This commit is contained in:
John Cupitt 2020-11-29 13:59:30 +00:00
parent acc579cc9d
commit 2585565b3e
2 changed files with 13 additions and 1 deletions

View File

@ -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]

View File

@ -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 )) )